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
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.
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
Summary: Hello, as part of a kornshell script I am trying to get the filename "arto.blah" out of this string assignStr: assignStr = "/sport/skate/arto.blah" I have tried the following to no avail: secondPart =...
Summary: Hi, I have this file look like this. I need to "break" it into two colums as dir. name and filename and also count number of sapce for the filename. All my file name extension is .cdd. /drawing/ckm0...