I have a complex command that I\'d like to make a shell/bash script of. I can write it in terms of $1
easily:
foo $1 args -o $1.ext
getopt Use command in your scripts to format any command line options or parameters.
#!/bin/bash
# Extract command line options & values with getopt
#
set -- $(getopt -q ab:cd "$@")
#
echo
while [ -n "$1" ]
do
case "$1" in
-a) echo "Found the -a option" ;;
-b) param="$2"
echo "Found the -b option, with parameter value $param"
shift ;;
-c) echo "Found the -c option" ;;
--) shift
break ;;
*) echo "$1 is not an option";;
esac
shift