Suppose I have the following script saved as runme.sh
usage() { echo "Usage: $0 [-s <integer>] [-l <string>]" 1>&2; exit 1; }
while getopts ":s:l:" o; do
case "${o}" in
s) s=${OPTARG}
[[ $s =~ ^-?[0-9]+$ ]] || usage ;;
l) l=${OPTARG} ;;
*) usage ;;
esac
done
echo "s = ${s}"
echo "p = ${p}"
This gives output as follows:
$ ./runme.sh -s x -l hello
Usage: ./runme.sh [-s <integer>] [-l <string>]
$ ./runme.sh -s 1 -l hello
s = 1
l = hello
Now compare this to the top answer from this thread. This latter script seems to run the same whether we have:
((s == 45 || s == 90))
or
(($s == 45 || $s == 90))
at line nine...
However, for my script I need the '$' in front of the s variable, or else it only gives the first output shown above, regardless of whether s is an integer. Why is this? I would assume it has something to do with the difference between [[ and (( but I can't seem to find a definitive answer.