Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Parameter Expansion
- X-seq: zsh-users 30305
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Parameter Expansion
- Date: Tue, 15 Jul 2025 16:16:56 +0100 (BST)
- Archived-at: <https://zsh.org/users/30305>
- Feedback-id: 20250715-p.w.stephenson@xxxxxxxxxxxx:oxsmtp-prd-nl-vmo:Authrelay:p.w.stephenson@xxxxxxxxxxxx
- Importance: Normal
- In-reply-to: <44d1a0ff-b701-459c-aeb4-6b71e7c6cd62@gmx.com>
- List-id: <zsh-users.zsh.org>
- References: <CACeGjnWw4=9Hm9k0iXSoLDRYCfVxEz=uYrQ6MyBouRbFBbf7yw@mail.gmail.com> <44d1a0ff-b701-459c-aeb4-6b71e7c6cd62@gmx.com>
> On 15/07/2025 16:01 BST Eric Cook <llua@xxxxxxx> wrote:
>
>
> On 7/15/25 10:44 AM, Vin Shelton wrote:
> > I don't understand the order of parameter expansion. Consider the following example:
> >
> > zsh -f
> > export HOME=/home/acs
> > smaug% export SCMROOT=/home/acs/scmroot
> > smaug% echo ${SCMROOT:s-$HOME/--}
> >
> > This yields /home/acs/scmroot", but I expected "scmroot".
> > TIA,
> > Vin Shelton
> >
>
> The history modifier doesn't create a new context where the parameter
> expansion code recurses and resolves any parameters within it's
> operands.
> It is searching for the literal string $HOME.
The fix is to use the parameter system's own substitution code, which
does recursively handle parameters. The easiest one to use in this case
is:
echo ${SCMROOT#$HOME/}
There are more general substitution commands but this fits the bill
here.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author