Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16673

Re: set -u not working as expected

From Oğuz <oguzismailuysal@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: set -u not working as expected
Date 2020-08-02 09:51 +0300
Message-ID <mailman.488.1596351081.2739.bug-bash@gnu.org> (permalink)
References <000301d66834$588493c0$098dbb40$@kalvr.net> <F4821044-5F8D-4B6D-A266-BAC88AE3DC2C@larryv.me> <1867D8FC-85DD-4406-A239-3002913493AB@larryv.me> <CAH7i3Lr7ZCYJVpPZdc9xQMuF_yc_C2q0S9px+NY4prEUkU+24w@mail.gmail.com>

Show all headers | View raw


2 Ağustos 2020 Pazar tarihinde Lawrence Velázquez <vq@larryv.me> yazdı:

> > On Aug 1, 2020, at 8:47 PM, Lawrence Velázquez <vq@larryv.me> wrote:
> >
> > Presumably none of these shells implements u+=(t) as u=("${u[@]}" t).
>
> Granted, they do disagree on ${u[@]}.
>
> % bash -c 'set -u; unset u; u=("${u[@]}" t); typeset -p u'
> declare -a u=([0]="t")
> % ksh -c 'set -u; unset u; u=("${u[@]}" t); typeset -p u'
> typeset -a u=(t)
> % zsh -c 'set -u; unset u; u=("${u[@]}" t); typeset -p u'
> zsh:1: u[@]: parameter not set
>
>
`u' has no members, so there's nothing to expand. If you use `${u[0]}' for
example, you'll see an error, I think how bash and ksh behave is perfectly
reasonable.


> > I haven't seen the code for arithmetic expansion, but I assume it
> > treats v+=1 as morally equivalent to v=${v}+1 (à la C99). Thus there
> > *is* an expansion, which fails under set -u. Regardless of the
> > particulars, ksh and zsh again agree:
> >
> > % bash -c 'set -u; unset v; let v+=1; printf "<%s>\\n" "$v"'
> > bash: v: unbound variable
> > % ksh -c 'set -u; unset v; let v+=1; printf "<%s>\\n" "$v"'
> > ksh: let: v: parameter not set
> > ksh: v: parameter not set
> > % zsh -c 'set -u; unset v; let v+=1; printf "<%s>\\n" "$v"'
> > zsh:1: v: parameter not set
> > zsh:1: v: parameter not set
>
> On the other hand...
>
> % bash -c 'set -u; typeset -i v; printf "<%s>\\n" "$v"'
> bash: v: unbound variable
> % ksh -c 'set -u; typeset -i v; printf "<%s>\\n" "$v"'
> ksh: v: parameter not set
> % zsh -c 'set -u; typeset -i v; printf "<%s>\\n" "$v"'
> <0>
>
>
`typeset -i v' doesn't assign `v', just gives it the integer attribute.
Again, I can't see any problem with bash and ksh here.


> ...and...
>
> % bash -c 'set -u; typeset -i v; v+=1; printf "<%s>\\n" "$v"'
> <1>
> % ksh -c 'set -u; typeset -i v; v+=1; printf "<%s>\\n" "$v"'
> <1>
> % zsh -c 'set -u; typeset -i v; v+=1; printf "<%s>\\n" "$v"'
> <1>
>
> *shrug*
>
> vq
>


-- 
Oğuz

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: set -u not working as expected Oğuz <oguzismailuysal@gmail.com> - 2020-08-02 09:51 +0300

csiph-web