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

Re: numeric for-loop and string for-loop



On 12/3/18, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> % a=5+5 b=2\*3
> % typeset -i i
> % for i in a b; do declare -p i; done; declare -p a b
> typeset -i i=10
> typeset -i i=6
> typeset a=5+5
> typeset b='2*3'
>
> If this is not what you want, you can use unset i before each loop.

In fact, bash will act the same way as zsh if you say "typeset -i i",
the only difference is that zsh will create parameters as integers in
a mathematical context if they did not previously exist. In other
words, your zsh script will also "work" if you do "typeset i" before
the first loop, because then it already exists when you get to the
math loop.

-- 
Mikael Magnusson



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