Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16675
| From | Oğuz <oguzismailuysal@gmail.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: set -u not working as expected |
| Date | 2020-08-02 11:01 +0300 |
| Message-ID | <mailman.500.1596355268.2739.bug-bash@gnu.org> (permalink) |
| References | (1 earlier) <F4821044-5F8D-4B6D-A266-BAC88AE3DC2C@larryv.me> <1867D8FC-85DD-4406-A239-3002913493AB@larryv.me> <CAH7i3Lr7ZCYJVpPZdc9xQMuF_yc_C2q0S9px+NY4prEUkU+24w@mail.gmail.com> <61B2CB9D-3978-4872-B88A-1542CF95B5B9@larryv.me> <CAH7i3LqAXNdCGjNqTGmnkimnXpz_kGnhQsiR2m7a5ezWtqe42A@mail.gmail.com> |
2 Ağustos 2020 Pazar tarihinde Lawrence Velázquez <vq@larryv.me> yazdı:
> > On Aug 2, 2020, at 2:51 AM, Oğuz <oguzismailuysal@gmail.com> wrote:
> >
> > `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.
>
> Agreed. Their behavior logically follows from POSIX's carveout for $@.
>
> >> % 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.
>
> Also agreed, but I was more interested in the next part...
>
> >> % 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>
>
> ...which contrasts with the behavior of let. Someone else will have
> to explain this, as I don't know what to make of it.
>
>
Yeah, that's interesting. See this one:
$ set -u
$ unset foo bar
$ typeset -i foo bar
$
$ foo+=foo+1
$
$ foo+=bar+1
bash: bar: unbound variable
Only referencing `bar' triggers the _unbound variable_ error, it makes
sense that the name being assigned is immune to that.
Concerning `let v+=1', let is not a declaration utility, it's arguments are
arithmetic expressions to be evaluated. And in arithmetic evaluation
context:
> Shell variables are allowed as operands; parameter expansion
> is performed before the expression is evaluated.
> vq
--
Oğuz
Back to gnu.bash.bug | Previous | Next | Find similar
Re: set -u not working as expected Oğuz <oguzismailuysal@gmail.com> - 2020-08-02 11:01 +0300
csiph-web