Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Issue with VAR=foo cmd where VAR is a named reference
- X-seq: zsh-workers 54957
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Issue with VAR=foo cmd where VAR is a named reference
- Date: Sat, 11 Jul 2026 17:05:22 -0700
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=n8U/R7CtiQ8cNyxBKq3tFrjxCXbin95yHzsEoyk90Sc=; fh=BgAYDYpL6Ne/A5nWEMVJiHiBtrz8Imz3uf26RDwgQX4=; b=agqiLP2P7eQCyhRKICl93Sua8JXzqou5sDYdCgEavv7+C/x2sZNRu1X3yf4Pcv+IW/ 96EpC5yUlaouZcanwhmeZO7G78ZXdaYdqM9VBQvxt4mDGCnXvchNENzJohiqUk226pLk 7eP07O4hayOCifD2ZqqYapWzZ4ddgKzDKqe+S42NZm5UvTxxKWW0PR1BktsKYXTbHKJy iWnmLwN97bRH08pdReccO7k2OrdkuO0ZqN/uAR+hWDj+v8CMAtB02r+DCITF+VyhJsFo I0FFZ19qGn1lFDTCsr3us2cH9C3u89FAYj1IXerO73H+w6GFylFg0sAFPI6HGV2Biu0p 8KEA==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1783814734; cv=none; d=google.com; s=arc-20260327; b=nn/vkk7v3BGZ8JCKZ1JP3+4MVBHNLW6XUtm0DmhHqMk/3S/Ijj3jetpv3XDT3QsQ/T kdwnpgQ/mfbBjw2fBt/nct24DRhaDc/r9ZikfdS5Rf/ALjEL/Fc/D/2BAnQlsA7Z3vAQ y6ZK7zqcD/I56888W7vQqHuzuwNeTW28K1HvXVoBcbxmjG7cgSoJCGp/HrmfqsRjSV5m zzSIlxDXdPADWWlCHOvvL6Vs60ZEEfObFNgJYqt1K5GE1LYKWfCqfFy/IqvS/7r6uFbc riXzfqB3vhNn/96p3jQOyxPUdoOMvlcxp8qdF+JAMoMCIzmcPKm0eZln1DywEthLyLRl IRWQ==
- Archived-at: <https://zsh.org/workers/54957>
- In-reply-to: <CAGdYchscFj-hUdKvuPNC0c05MNE9xHGRiW1mRMFLpb5JbrVLsw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchvh5Q+wG5au4=+-VDkZyvdu19-ac5gWsM-ZEGQm2_bgpw@mail.gmail.com> <CAH+w=7aapgt4Ag+ke-XHNy9XC8--nWH6eNTDWT=38PCHZUXk4g@mail.gmail.com> <CAGdYchsM9JbZT4W9qdGSB7eT6X-=WiCj1wmd_ynb=m9uSys5Hw@mail.gmail.com> <CAHYJk3ShjiOya2GnaoE+Jxh=24RU3kGvEWrf7YoDjt4Y300nGQ@mail.gmail.com> <CAGdYchvto8bOjthzQXQ1K+_uXiRTuSnny1+=rd4e6az-3gw8aA@mail.gmail.com> <CAGdYchscFj-hUdKvuPNC0c05MNE9xHGRiW1mRMFLpb5JbrVLsw@mail.gmail.com>
On Fri, Jul 10, 2026 at 6:39 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> Bart suggested that "var=foo cmd" ought to be the same as running "cmd" in a scope augmented with an exported local "var" parameter: "() { local -x var=foo; cmd }". However, this is incompatible with the current behavior. Indeed, the type of the assigned parameters is preserved. For example, "typeset -i var; var=10+1 printenv var" is equivalent to "typeset -i var; () { local -x -i var=10+1; printenv var }". My proposal is to do the same for references, such that "typeset -n ref=foo; ref=bar cmd" is equivalent to "typeset -n ref=foo; () { local -n ref=bar; cmd }".
This seems to me to be in direct conflict with the (reasonable)
assertion in workers/54943 that references should not be exported, and
also with workers/54948 where you question why inline assignments
differ from ALL_EXPORT. The reasoning behind my suggestion (above)
was that inline assignments should always yield something that
actually goes into the environment: the -x flag in the "as if local
-x" is important, and your proposal discards it in the case of
references.
I'd be more inclined to believe that preservation of (for example)
integer-ness is an accident than an intention with respect to inline
assignments, that it occurs only because scalar-ness is preserved.
Certainly integer-ness etc. is not preserved when the command is
external.
When the inline assignment is for a parameter declared as an array the
type of the assigned parameter is not preserved:
% typeset -a foo=(a 2 z)
% foo=bar /usr/bin/printenv foo
bar
% foo=bar printenv foo
bar
% f() { typeset -p foo; printenv foo }
% foo=bar f
export foo=bar
bar
I think this should apply to anything that can't be exported, so if a
reference can't be exported then an inline assignment to a reference
should temporarily hide it behind a scalar.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author