pure-bash-bible
pure-bash-bible copied to clipboard
Parsing and passing around command line arguments
I am fond of this:
HELP_TEXT="Usage: [-f|--foo-bar] [-o] baz"
for i in "$@"
do
case $i in
-f=*|--foo-bar=*)
FOOBAR=" --other-scripts-flag=${i#*=}"
shift # past argument=value
;;
-o)
OTHER=" -o"
shift # past argument=value
;;
*)
echo "$HELP_TEXT"
exit 1
;;
esac
done
./other_script.sh${FOOBAR}${OTHER}
I got this from https://stackoverflow.com/a/14203146/881224
But what is it replacing? Bash has the getopts builtin.