On Fri, Jan 25, 2013 at 9:16 PM, Ken Irving
<address@hidden> wrote:
I stumbled on this case where the ## parameter expansion isn't as greedy
as I thought it should be:
$ opt=--foo
$ echo ${opt} ${opt#-} ${opt##-}
--foo -foo -foo
$ echo $BASH_VERSION
4.1.5(1)-release
There's nothing special about the dashes here, as the same result is seen
if some other character is used for the prefix. Perhaps the reason is
that a single character is not a 'pattern',
You're right it's not a pattern.
It seems to me that the pattern [-] ought to behave as I expect, with
${opt#[-]} removing one '-' and ${opt##[-]} both or all prefix dashes,
but hesitate to say this is a bug in anything but my understanding.
[-] is a pattern but it can match only one single - char. Following is what you want:
$ shopt -s extglob
$ opt=--foo
$ echo ${opt##+(-)}
foo
$