Computing.Net > Forums > Unix > no filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

no filename

Reply to Message Icon

Name: Debbie
Date: October 19, 2002 at 08:00:24 Pacific
OS: Win2000
CPU/Ram: AMD Athlon
Comment:

consider the following situation:
$ myscript filename
if the user enter more than one filename, eg:
$ myscript filename filename1
, then echo "error"
else, if the user enter no filename, eg:
$ myscript
, then the user is given one more chance to enter the filename again, if the second time the user enter no filename again, then the myscript will exit, but if the user enter more than one filename for the second time, then the echo "error" mentioned before will be displayed.



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: October 19, 2002 at 08:43:37 Pacific
Reply:

Here is that logic using a case statement:

#!/bin/sh
case $# in
1) filename=$1;;
0) echo "Please enter filename: \c"
read filename morestuff
if [ -z "$filename" ] ; then
exit
fi
if [ -n "$morestuff" ] ; then
echo error
exit 1
fi;;
*) echo error
exit 1;;
esac

echo "Will now process $filename ..."
exit 0

And without using a case statement ...

#!/bin/sh

if [ $# -gt 1 ] ; then
echo error
exit 1
fi

if [ $# -eq 1 ] ; then
filename=$1
else
echo "Please enter filename: \c"
read filename morestuff
if [ -z "$filename" ] ; then
exit
fi
if [ -n "$morestuff" ] ; then
echo error
exit 1
fi
fi

echo "Will now process $filename ..."
exit 0


0

Response Number 2
Name: Don Arnett
Date: October 19, 2002 at 11:41:45 Pacific
Reply:

I considered the situation. What's the question?


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: no filename

Korn script help!! www.computing.net/answers/unix/korn-script-help/4858.html

AWK get filename www.computing.net/answers/unix/awk-get-filename/7024.html

Extract Filename + number of space www.computing.net/answers/unix/extract-filename-number-of-space/5317.html