By zaq1xsw2
Hi,
Here is my code as below:
test.ksh:
=======
Code:
#!/bin/ksh
option="${1}"
while [ $# -gt 0 ]
do
case $1 in
-f) FILE="${2}"
echo "File name is $FILE"
;;
-d) DIR="${2}"
echo "Dir name is $DIR"
;;
-*)
echo "`basename ${0}`:usage: [-f file] | [-d directory]"
exit 1 # Command to come out of the program with status 1
;;
*) ;;
esac
shift 1
done
While i am running the above script:
Code:
[kanix@voodoo mydir]$ ./test.ksh -f "abc.txt"
File name is abc.txt
The above output is as expected.. But when i am running as below:
Code:
[kanix@voodoo mydir]$ ./test.ksh -f "-abc.txt"
File name is -abc.txt
test.ksh:usage: [-f file] | [-d directory]
the usage code is getting displayed.. which is not expected..
But again when i am providing a space between the quote and hyphen it is again showing the expected result.
Code:
[kanix@voodoo mydir]$ ./test.ksh -f " -abc.txt"
File name is -abc.txt
Please advise why this is happening and how to fix this.. i need to run the code as : ./test.ksh -f “-abc.txt”
…read more
Source: FULL ARTICLE at The UNIX and Linux Forums