My script has an option o
, which should accept argument as value, as below
./script -o '-p 2' ls
but getopt is not allowing, giving an error
Unrecognized option '-p 2'
code snippet:
ARGS=$(getopt -a -n $0 -o o::h -- "$@")
eval set -- "$ARGS"
while true
do
case "$1" in
-o) opt="$2"; echo "options: $2"; shift; shift;;
-h) echo "$usage"; exit 0;;
--) cmd="$2"; shift; break;;
esac
done
How can I pass arguments as value to script?