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

Re: arithmetic expression from outside



On Thu, Sep 5, 2019 at 1:50 AM YAMAGUCHI Takanori <t-yama@xxxxxxxxx> wrote:
>
> Is this an intended behaviour?

It's the way evaluation of variables in math expressions is defined,
yes.  Similarly in ksh:

% echo 'sum[$(echo Hello, world!>&2)]' | ksh -c 'read n; echo $((n))
Hello, world!
ksh: sum: parameter not set

Also environment variables:

% N='sum[$(echo Hello, world!>&2)]' ksh -c 'echo $((N))'
Hello, world!
ksh: sum: parameter not set

(I have a 2012 ksh so maybe this is different now.)

Bash 3.2.57 does the same, although without complaining about the
unset parameter:

% N='sum[$(echo Hello, world!>&2)]' bash -c 'echo $((N))'
Hello, world!
0

Zsh at least does not do that with parameters from the environment,
although I'm not exactly sure what prevents it.



Messages sorted by: Reverse Date, Date, Thread, Author