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

Re: for loop 'bad math expression'



On Sat, Feb 3, 2024 at 6:06 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:
>
> On Sat, Feb 3, 2024, at 8:14 PM, Ray Andrews wrote:
> > 0 /usr/share/info 0 % var=abc; let var+=2; echo $var
> >
> > 2
> > ... it looks like the shell is simply throwing away 'abc' and starting
> > afresh with an integer and then incrementing it.
>
> No, that's not what happens.  Within arithmetic expressions, the
> contents of variables undergo recursive arithmetic evaluation

This has been a very thorough description of the arithmetic process in
zsh, but I think misses one important detail:

% var=abc
% typeset -p var
typeset var=abc
% let var+=2
%  typeset -p var
typeset var=2

Note that var has NOT acquired the "-i" (integer) attribute, despite
having been assigned a number value.




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