In a script which request some arguments (arg) and options (-a), I would like to let the script user the possibility to place the options where he wants in the command line.
Here is my code :
while getopts "a" opt; do
echo "$opt"
done
shift $((OPTIND-1))
echo "all_end : $*"
With this order, I have the expected behaviour :
./test.sh -a arg
a
all_end : arg
I would like to get the same result with this order :
./test.sh arg -a
all_end : arg -a
tail file -n 5andtail -n 5 fileworks.$@and remove all non-option arguments.getoptson its own won't be able to support what you're asking for.getops_longlibrary call for options processing (or something entirely different; most languages have their own standard -- or multiple -- options processing modules). You could of course write your own options processing routine in shell script that does what you want.