Why does the recursive expansion of foo not trigger an error message with the -u option? Is that a bug? Is there some woraround to get the expected error behaviour in all cases? -- snip -- set -u foo=bar unset bar # ==> bar: parameter not set echo $bar # ==> no error? echo ${${foo}} -- snip -- $ zsh --version zsh 5.3.1 (x86_64-...-...-gnu) Ciao Dominik ^_^ ^_^ -- Dominik Vogt
On 2/15/19, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> Why does the recursive expansion of foo not trigger an error
> message with the -u option? Is that a bug? Is there some
> woraround to get the expected error behaviour in all cases?
>
> -- snip --
> set -u
> foo=bar
> unset bar
> # ==> bar: parameter not set
> echo $bar
> # ==> no error?
> echo ${${foo}}
> -- snip --
If the above command doesn't output bar, your shell is very broken. I
think you're confused about what ${${foo}} means though. Putting a ${}
inside another ${} doesn't perform indirect expansion, you need (P)
for that.
--
Mikael Magnusson
On Fri, Feb 15, 2019 at 12:45:28AM +0100, Mikael Magnusson wrote:
> On 2/15/19, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> > Why does the recursive expansion of foo not trigger an error
> > message with the -u option? Is that a bug? Is there some
> > woraround to get the expected error behaviour in all cases?
> >
> > -- snip --
> > set -u
> > foo=bar
> > unset bar
> > # ==> bar: parameter not set
> > echo $bar
> > # ==> no error?
> > echo ${${foo}}
> > -- snip --
>
> If the above command doesn't output bar, your shell is very broken. I
> think you're confused about what ${${foo}} means though. Putting a ${}
> inside another ${} doesn't perform indirect expansion, you need (P)
> for that.
Yeah, you're right. My memory believes this was different at some
distant point in the past, i.e. that ${${A}} used to do recursive
expansion.
Well, with (P) it's possible to do recursive expansion at the
right side of an assigntment, but can you also do soething like
foo=bar
${foo}=baz
i.e. treat the contents of foo as the lvalue of an assignment?
(Without using eval, of course.)
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
On Thu, Feb 14, 2019 at 4:47 PM Dominik Vogt <dominik.vogt@gmx.de> wrote:
>
> Well, with (P) it's possible to do recursive expansion at the
> right side of an assigntment, but can you also do soething like
>
> foo=bar
> ${foo}=baz
>
> i.e. treat the contents of foo as the lvalue of an assignment?
Not directly, but you can do
typeset ${foo}=baz
On Thu, Feb 14, 2019 at 6:47 PM Dominik Vogt <dominik.vogt@gmx.de> wrote:
>
> Well, with (P) it's possible to do recursive expansion at the
> right side of an assigntment, but can you also do soething like
>
> foo=bar
> ${foo}=baz
>
> i.e. treat the contents of foo as the lvalue of an assignment?
> (Without using eval, of course.)
% foo=bar; : ${(P)foo::=baz}; typeset -p bar
typeset bar=baz