Created
December 15, 2021 06:35
-
-
Save ksc91u/69dbe219864dda922cb69ef5db9d291f to your computer and use it in GitHub Desktop.
Zsh Bash difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat /tmp/tmp | |
1 | |
2 | |
10 | |
9 | |
Bash: | |
D is array | |
bash-3.2$ D=`cat tmp` | |
bash-3.2$ for i in $D; do echo "x$i"; done | |
x1 | |
x2 | |
x10 | |
x9 | |
Zsh: | |
D is not array | |
$ D=`cat tmp` | |
$ for i in $D | |
do | |
echo "x$i" | |
done | |
x1 | |
2 | |
10 | |
9 | |
Zsh correct way: | |
$ for i in `cat tmp` | |
do | |
echo "x$i" | |
done | |
x1 | |
x2 | |
x10 | |
x9 | |
Zsh correct way 2: | |
$ Z=("${(@f)$(cat tmp)}") | |
$ for i in $Z | |
do | |
echo "x$i" | |
done | |
x1 | |
x2 | |
x10 | |
x9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment