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

RE: cat file|while read behaves not as expected



>>>>> "Micha" == Micha Holzmann <holzmann@xxxxxxxx> writes:

    Micha> #!/bin/zsh

    Micha> cat ./tst.dat|while read line
    Micha> do
    Micha> for i in $line
    Micha> do
    Micha> echo $i
    Micha> done
    Micha> done

    Micha> If i run this script, it prints "1 2 3 4 5" as result, if i
    Micha> change the shell to /bin/sh, it prints (te expected)
    Micha> result:

    Micha> 1
    Micha> 2
    Micha> 3
    Micha> 4
    Micha> 5

    Micha> What is the fault i make?

if you say:

    for i in $=line

it will do what you want.  Basically, the variable i will contain the
"1 2 3 4 5", unless you told it to split word, the entire entry is
will be used on variable expansion.  This is what zsh does it
correctly compare to other shells, but also a problem with
compatibility :-)



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