Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
numeric for-loop and string for-loop
- X-seq: zsh-users 23785
- From: Peng Yu <pengyu.ut@xxxxxxxxx>
- To: zsh-users <zsh-users@xxxxxxx>
- Subject: numeric for-loop and string for-loop
- Date: Mon, 3 Dec 2018 07:56:26 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=c5wzklsFzXYJ8efMXZjC6lQHuZhRwZj+8FmZQi+A/zE=; b=kgqB4DSCCkENcCadQTPgx/vot1d3XmLCh5ReGA1If5VN+QtQAgrfz/oVxBnwJkXBBw Sul3sRGFWU1Z29nZ6KfoMPT6L+9biu6WoE68Pc/actsX0dyLitsskNRINR3sjWKSLMIR MIw0P0vPa1XyhdkzjxGyK43EZAPTpZKa0W571F35lcKlK5L4gXdMMpztWM0EGestvz2q wCTox2twgcnJqxV1G0Tpr5BMAWNmVQ8Gg4sS/XVqLP0aKYpameVdQawCR6fsz6/C+BpG NEjXS0m+uWNwolZ7GI9nEZh8TJeeqw0ESt0aYHPQuM8xlVitTyyXKRnBRM0YsWfUCOQy IcDA==
- 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
Hi,
The following zsh and bash code generate different resutls. I feel the
bash convention is better.
To make the second i as string in zsh, what is the best solution so
that the minimum amount of code is changed. (I'd rather not to change
the second `i` to some other variable name as each for-loop should be
independent from each other, and should not know each other to make
the code work.). Thanks.
$ cat main.sh
#!/usr/bin/env zsh
# vim: set noexpandtab tabstop=2:
set -v
for ((i=0;i<2;++i))
do
echo $i
done
declare -p i
for i in a b
do
declare -p i
done
$ cat main.bash
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
for ((i=0;i<2;++i))
do
echo $i
done
declare -p i
for i in a b
do
declare -p i
done
$ ./main.sh
for ((i=0;i<2;++i))
do
echo $i
done
0
1
declare -p i
typeset -i i=2
for i in a b
do
declare -p i
done
typeset -i i=0
typeset -i i=0
$ ./main.bash
for ((i=0;i<2;++i))
do
echo $i
done
0
1
declare -p i
declare -- i="2"
for i in a b
do
declare -p i
done
declare -- i="a"
declare -- i="b"
--
Regards,
Peng
Messages sorted by:
Reverse Date,
Date,
Thread,
Author