This is correct behaviour. Perhaps these two examples will make it more
clear.
$ OPTIND=1
$ while getopts :a:bc f -a foo -b -c bar; do
> echo "f=$f arg='$OPTARG'"
> done
f=a arg='foo'
f=b arg=''
f=c arg=''
$
$ OPTIND=1
$ while getopts :a:bc f '-a foo -b
I have slept on this and I think bash is working correctly.
If you put "-a test -b -c" all inside quotes it will be treated as a single
flag/argument. Leave out the quotes and it will treat it as separate
arguments. So below "-a test -b -c" is one argument; -b and -c are the second
and third
getopts is a bash builtin.
** Package changed: ubuntu => bash (Ubuntu)
--
Bash script getopts strange behaviour
https://bugs.launchpad.net/bugs/522591
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
--
ubuntu-bugs mailing list
ubuntu-b
I get the same response on Ubuntu and Gentoo.
I am not a bash expert but would make the observation that (note multiple
quotes):
#!/bin/bash
while getopts "a:bc" flag '-a test' '-b' '-c'; do
echo "$flag $OPTARG"
done
in test2 will generate:
pe...@vostro ~/Desktop $ ./test2.sh
a test
b
c
a