help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] confusion with double-hash parameter expansion


From: Clark WANG
Subject: Re: [Help-bash] confusion with double-hash parameter expansion
Date: Fri, 25 Jan 2013 21:40:35 -0700

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
$

reply via email to

[Prev in Thread] Current Thread [Next in Thread]