Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Unable to process a for loop as expected??

>list="a b c d"
>for character in $list

You're trying to have word splitting done on $list, in order to
generate multiple words for the for loop.  By default zsh does no field
splitting.  There are three main approaches to this problem.

1. In order to get sh behaviour in this regard, use "setopt
sh_word_split".  ("emulate sh" will do this, among other things, and
zsh will have this option set by default if invoked as sh.)

2. In order to do field splitting here only, leaving the default
behaviour unchanged, use $=list instead of $list.

3. In order to make the script use idiomatic zsh, rewrite it using an

list=(a b c d)
for character in $list

This last method has the advantage that the values to be looped over
can contain whitespace:

list=(a b c 'd and some more text with spaces')

>BTW, according to the extracted sources, I am using zsh version zsh-2.6-beta19.
>However, according to the man pages, I am using zsh version 2.7.  (Why 
>the discrepancy?)

For a while the man pages said 2.7 because that was expected to be the
next public release, and it would be too much trouble to change the man
pages every version.  The latest release is 3.0.0, and the man pages
say 3.0.

>I am running the LINUX operating system, version 1.3.91.

Not a terribly stable version, AFAIK.  Apparently 1.3.98 and 1.3.100
are much better.  (I'm still running 1.3.80 -- very stable.)


Messages sorted by: Reverse Date, Date, Thread, Author