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

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



On Monday July 23 2001 03:36, Osamu Aoki wrote:
> Hi,
>
> 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?
>
> $ XXX="123456123456"
> $ echo $XXX
> 123456123456
> $ echo ${XXX%%*1}
> 123456123456
> $ echo ${XXX%%*6}
>
> $ echo ${XXX%*1}
> 123456123456
> $ echo ${XXX%*6}
> 12345612345
> $ echo ${XXX##*1}
> 23456
> $ echo ${XXX#*1}
> 23456123456
>
> ??????????????????????????


>From http://www.gnu.org/manual/bash-2.02/html_mono/bashref.html

${parameter%%word} 
The word is expanded to produce a pattern just as in filename expansion. If 
the pattern matches a trailing portion of the expanded value of parameter, 
then the result of the expansion is the value of parameter with the shortest 
matching pattern (the `%' case) or the longest matching pattern (the `%%' 
case) deleted. If parameter is `@' or `*', the pattern removal operation is 
applied to each positional parameter in turn, and the expansion is the 
resultant list. If parameter is an array variable subscripted with `@' or 
`*', the pattern removal operation is applied to each member of the array in 
turn, and the expansion is the resultant list. 

HTH,
Andy



Reply to: