Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug on parameter expansion when set -u is in effect




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