[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Q: bash parameter expansion
From: |
Dmitry V. Levin |
Subject: |
Re: Q: bash parameter expansion |
Date: |
Mon, 21 Apr 2008 15:35:03 +0400 |
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.
--
ldv
pgpGEYdPkCASi.pgp
Description: PGP signature