Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: numeric for-loop and string for-loop
- X-seq: zsh-users 23789
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Peng Yu <pengyu.ut@xxxxxxxxx>
- Subject: Re: numeric for-loop and string for-loop
- Date: Mon, 3 Dec 2018 15:58:50 +0100
- Cc: zsh-users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=184tWgCLG1I7IPDcl068ZZP88pkKNzai44WSOkeTK0s=; b=ZXzEvnhg3xjZ4jlP3BNp4KdHPSzDrD3+DpyxWmJRZ6QeBlkw7Jmi/cyDhc0DRRTQAD AB75SYbja84jc62L8gjuxfVlj9q3u2QpEgObbhERVVUNvHdHj2tUvEC1RFWBs6JF3PnC e/TzkNy6OjRkTkaaltV2Ik4I7K5qm41rp7z+JzwRZm5ozg4lrrcc2HUxLAUJp6NK8SSz fn8UzPgfwmtSivzlZdcSZISy9COaDrXQMrGiJCNYxo58r7sQF/mdAzzN5/OI9y3WPvcM lPvVkj82XS1HMCZk8w1TcmYzOUCyKYhQQc8gTo212LtqKrzBcvsXFMiW9tBCx/cynJO0 9dbA==
- In-reply-to: <CAHYJk3R7OvA07chXGWmkMpSi0fB21z06V-2BJ5=3R+_14GJAew@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABrM6wnW1cap8rP8oW8rbRd00eByL86aQq0gXsn0mmg6Tirn0g@mail.gmail.com> <CAHYJk3R7OvA07chXGWmkMpSi0fB21z06V-2BJ5=3R+_14GJAew@mail.gmail.com>
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