I have a shell script where i am parsing command line argument. My arguments has path in it.
Example: mycript.sh -c test -s global -n /mydir/test1 -d /orgdir/test35
When I run the script and echo the arguments which contains path(special char "/"), it gives me empty path.
#/!bin/bash
...
while getopts c:hs:n:d opt
do
case "$opt" in
c) INST=$OPTARG;;
d) INST_DIR=$OPTARG;;
h) usage;;
s) METHOD=$OPTARG;;
n) MAINTENANCE_DIR=$OPTARG;;
\?) usage;;
esac
done
echo INST dir is [$INST_DIR]
echo MAINTENANCE dir is [$MAINTENANCE_DIR]
.......
Result of this echo is
INST dir is []
MAINTENANCE dir is []
Can someone tell what is incorrect here?
docoptis still a 3rd-party solution, though.getoptsis part ofbash, and so is completely portable (given the assumption thatbashis available, anyway).