Hello, I was hoping for a second pair of eyes or a little bit of help figuring out what my error is in a script. I did some searching in the forums and didn't find anything so please forgive me if it a similar problem has been discussed before.
My script accepts normal user arguments; however, the two formats I am using are returning bad substitution errors. I could do fix it the old fashioned way with more code but I would prefer to try to figure out what is wrong with my current syntax.
Here are the snippets from the two formats I am trying to use:
while [ "$1" != "" ]
do
if [ "${1:0:1}" = "-" ]; then
case "$1" in
"-v") echo "$VERSION"
exit
;;
"-h") #echo help usage
;;
"-s") #do stuff
shift
;;
*)
usage "Argument not recognized: $1"
;;
esac
fi
shift
done
2nd example:
while [ "${1:0:1}" = "-" ]; do
case ${1:1:1} in
"v") echo "$VERSION"
exit
;;
"h") #echo help usage
;;
"s") #do stuff
shift
;;
*)
usage "Argument not recognized: $1"
;;
esac
done
My error code:
[script name] [line_number]: Bad substitution
The line_number corresponds with the done in the loops but it's definitely with the ${1:0:1} syntax, which doesn't make sense because it's valid (at least unless my eyes are missing something).
Thanks for any help I can get!