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

Re: bash ${parameter%%patern} does not work ?



Osamu Aoki <debian@aokiconsulting.com> writes:

> I have been scratching my head for bash parameter substitution.
> 
> I understand ## in following examples but I can not understand %%.
> Is this how bash 2.0 supposed to work?

[examples deleted]

The examples you give do not really illustrate what exactly you don't
understand about this form of parameter expansion.  The bash
documentation is very good in this field anyway (see "man bash", or
the texinfo docs in the bash-doc package).

Maybe this table helps demonstrate the difference between the four
forms:
                          match type
                      |longest|shortest|
                ------+-------+--------+     
                start |  ##   |   #    |
Anchor match to ------+-------+--------+
                end   |  %%   |   %    |
                ------+-------+--------+

In each case, if there is an appropriate match for the pattern in the
value of the variable being expanded, then the matching string is
removed from the value of the expansion, otherwise the value of the
variable is returned as a whole.

e.g. ${PATH%%:*} returns the first directory in the path.

If you still don't understand something after reading the relevant
parts of the documentation, post examples where bash behaviour
deviates from what you expect, and explain what you though would
happen.

-- 

Leonard Stiles <ljs@uk2.net>



Reply to: