Skip to content

Instantly share code, notes, and snippets.

@ksc91u
Created December 15, 2021 06:35
Show Gist options
  • Save ksc91u/69dbe219864dda922cb69ef5db9d291f to your computer and use it in GitHub Desktop.
Save ksc91u/69dbe219864dda922cb69ef5db9d291f to your computer and use it in GitHub Desktop.
Zsh Bash difference
$ 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