bug-bash
[Top][All Lists]
Advanced

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

Re: Q: bash parameter expansion


From: Andreas Schwab
Subject: Re: Q: bash parameter expansion
Date: Mon, 21 Apr 2008 10:06:10 +0200
User-agent: Gnus/5.110008 (No Gnus v0.8) Emacs/22.1 (gnu/linux)

"Dmitry V. Levin" <ldv@altlinux.org> 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.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

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