I'm writing a bash shell script that can use the flags -l -u and -w [argument]
I have the following (simplified) code:
while getopts ":ulw:" arg; do
case "$arg" in
u)
U=1
;;
l)
L=1
;;
w)
W=1
VALUE="${OPTARG}"
;;
esac
done
when I run my script with -w42 -l it works like it should. If I use -lw42 it also works but when I use -w42l, it thinks 42l is the argument (instead of just 42) and it makes the VALUE variable = 42l and ignores the -l option.
How can I make the script work for both -w42 -l, -lw42 and -w42l?
EDIT: to clear things up, I know this isn't the way it's supposed to work but my college requires me to make it work this way