I wrote about for each feature in bash, sh and zsh, I mean loop for a list. You know, there’s no for each
statement in bash, sh or zsh.
for sh and bash
The following code works in sh and bash.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
list="abc def ghi" for v in $list; do echo $v echo "/" done # = OUTPUT = # abc # / # def # / # ghq # / |
In sh and bash, space splits items. However, space doesn’t work as splitter in zsh.
bash
In zsh, generate list like the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
list=("abc" "def" "ghi") for v in $list; do echo $v echo "/" done # = OUTPUT = # abc # / # def # / # ghq # / |
The zsh code is similar to LL like Ruby and PHP, etc.