Iterate twice on bash scripts arguments using getoptex -
i'm writing bash script needs long arguments, --argument , not letters -a. there function called getoptex can found here can handle this.
the thing is, project specific modular. single script called, , need iterate on arguments find option tell me source script, has specific options , needs parse arguments again. there around 5 differents subscripts, each ones whith own options.
but first iteration on $@ seems erase every arguments , options (but leaves arguments without options), can't parse twice !
i'm giving code sample see i've done.
#!/bin/bash source ./getopt.sh echo "$@" while getoptex "a; b;" "$@" if [ "$optopt" = "a" ]; echo "a" elif [ "$optopt" = "b" ]; echo "b" fi done shift $[optind-1] arg in "$@" echo "$arg" done optind=1 unset optofs echo "$@" while getoptex "a; b;" "$@" if [ "$optopt" = "a" ]; echo "a" elif [ "$optopt" = "b" ]; echo "b" fi done shift $[optind-1] arg in "$@" echo "$arg" done but never parses second time... idea ?
leave out first call shift. usually, use remove arguments you've parsed, since want parse them twice, don't want remove after first pass.
by way, $[optind-1] obsolete; use $((optind-1)) instead.
Comments
Post a Comment