Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug on parameter expansion when set -u is in effect
- X-seq: zsh-workers 54173
- From: "Ronald Fischer" <ynnor@xxxxx>
- To: "Mikael Magnusson" <mikachu@xxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: Bug on parameter expansion when set -u is in effect
- Date: Thu, 05 Feb 2026 14:31:20 +0100
- Archived-at: <https://zsh.org/workers/54173>
- Feedback-id: ib78041aa:Fastmail
- In-reply-to: <CAHYJk3Ts8syjqjpVP5=AQ_atJUzcgFvcV7idsj_M2PTE++AF5g@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <c0faa0a6-4b7d-4820-9add-ca1c99e2aef6@app.fastmail.com> <CAHYJk3Ts8syjqjpVP5=AQ_atJUzcgFvcV7idsj_M2PTE++AF5g@mail.gmail.com>
On Thu, Feb 5, 2026, at 13:55, Mikael Magnusson wrote:
> On Thu, Feb 5, 2026 at 12:11 PM Ronald Fischer <ynnor@xxxxx> wrote:
>>
>> Using zsh 5.8.1 (x86_64-apple-darwin21.0)
>>
>> Consider the following fragment of code:
>>
>> kv="a b"
>> k=${kv%% *}
>> v=${kv##${k} #}
>>
>> This would set k to "a" and v to "b", and indeed usually does so.
>>
>> However, when I run this code with
>>
>> set -u
>>
>> in effect, the variable v is set to "a b" instead of "b".
>>
>> I think this is a bug, because all variables are assigned a value before they are expanded, so -u should not have any effect.
>
> It would be, but it is in fact not affected by set -u. Did you forget
> to setopt extendedglob in your test environment?
Aside from the set -u, no difference. Actually, I have put this in a script, to make sure that other settings from my shell don't effect it.
Actually, extendedglob is not needed, because the ' #' is inside the parameter expansion braces, and in this context, extendedglob is implicitly assumed - independent of the shell settings.
Ronald
--
Ronald Fischer <ynnor@xxxxx>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author