zsh-users
 help / color / mirror / code / Atom feed
* cat file|while read behaves not as expected
@ 2002-09-16  6:32 Micha Holzmann
  2002-09-16  6:52 ` Paul Lew
  0 siblings, 1 reply; 3+ messages in thread
From: Micha Holzmann @ 2002-09-16  6:32 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]

Hello,

i am new with zsh. I recently switched from bash to zsh. Now i stuck in
a little problem.

I use a file as configuration for a script. I read this file via cat and pipe
the result to while read...

The file content (example) is:

>---  cut here  ----
1 2 3 4 5
>---  cut here  ----

My script (a fragment from):

>---  cut here  ----
#!/bin/zsh

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


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

1
2
3
4
5

What is the fault i make?

Thanks in advance for any respones,
kind regards,
Micha Holzmann

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: cat file|while read behaves not as expected
  2002-09-16  6:32 cat file|while read behaves not as expected Micha Holzmann
@ 2002-09-16  6:52 ` Paul Lew
  2002-09-16  7:45   ` Micha Holzmann
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Lew @ 2002-09-16  6:52 UTC (permalink / raw)
  To: Micha Holzmann; +Cc: zsh-users

>>>>> "Micha" == Micha Holzmann <holzmann@mhnet.de> 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 :-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: cat file|while read behaves not as expected
  2002-09-16  6:52 ` Paul Lew
@ 2002-09-16  7:45   ` Micha Holzmann
  0 siblings, 0 replies; 3+ messages in thread
From: Micha Holzmann @ 2002-09-16  7:45 UTC (permalink / raw)
  To: Paul Lew; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

Hello Paul,

Quoting Paul Lew <paullew@cisco.com>:
> 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 :-)

so many thanks! Now my script runs how i expect it.
Also thanks to David Hughes!

Kind regards,
Gruss,
Micha Holzmann

-- 
My software never has bugs. It just develops random features.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-09-16  7:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-16  6:32 cat file|while read behaves not as expected Micha Holzmann
2002-09-16  6:52 ` Paul Lew
2002-09-16  7:45   ` Micha Holzmann

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).