pure-bash-bible icon indicating copy to clipboard operation
pure-bash-bible copied to clipboard

Parsing and passing around command line arguments

Open Droogans opened this issue 7 years ago • 1 comments

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

Droogans avatar Aug 09 '18 14:08 Droogans

But what is it replacing? Bash has the getopts builtin.

pawamoy avatar Apr 04 '19 21:04 pawamoy