bug-bash
[Top][All Lists]
Advanced

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

Re: Q: bash parameter expansion


From: Chet Ramey
Subject: Re: Q: bash parameter expansion
Date: Mon, 21 Apr 2008 08:56:29 -0400
User-agent: Thunderbird 2.0.0.12 (Macintosh/20080213)

Dmitry V. Levin wrote:
On Mon, Apr 21, 2008 at 10:06:10AM +0200, Andreas Schwab wrote:
Dmitry V. Levin writes:

I wonder whether such difference in parameter expansion is valid:

$ env -i sh -c 'fun() { echo "[${*#foo }]"; }; fun foo bar'
[foo bar]
$ env -i sh -c 'fun() { echo "[${*#foo}]"; }; fun foo bar'
[ bar]
Works as documented:

`${PARAMETER#WORD}'
`${PARAMETER##WORD}'
     The WORD is expanded to produce a pattern just as in filename
     expansion (*note Filename Expansion::).  If the pattern matches
     the beginning of the expanded value of PARAMETER, then the result
     of the expansion is the expanded 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.

Ouch, one more documented incompatibility between bash and dash.

Posix leaves it unspecified.  Bash and ksh do it one way; ash/dash and
zsh another.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                       Live Strong.  No day but today.
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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