Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Feb 2001 06:20:50 +0800
From:      Ariff Abdullah <skywizard@time.net.my>
To:        Stijn Hoop <stijn@win.tue.nl>
Cc:        freebsd-questions@FreeBSD.org
Subject:   Re: read in /bin/sh & pipes [was Re: sed & awk help...?!]
Message-ID:  <01020806275703.25931@FreeBSD.mine.nu>
In-Reply-To: <20010207225303.B12534@pcwin002.win.tue.nl>
References:  <054F7DAA9E54D311AD090008C74CE9BD01F1E94E@exchange.panasonicfa.com> <01020804390900.25931@FreeBSD.mine.nu> <20010207225303.B12534@pcwin002.win.tue.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 08 Feb 2001, Stijn Hoop wrote:
> Hi,
> 
> This is not really related to the original problem, but is more
> of a general /bin/sh question.
> 
> On Thu, Feb 08, 2001 at 04:36:07AM +0800, Ariff Abdullah wrote:
> > #!/bin/sh
> > while read a b c ; do
> > 	echo "==> line is: $a $b $c"
> > 	if [ "$a" = "$b" ]; then
> > 		echo "    $c"
> > 	fi
> > done < /where/is/the/file/it/should/read
> 
> Looks nice, haven't tested it. But when I saw this I tried to experiment
> with parsing stdin with read. Here's a transcript:
> 
> $ unset bla
> $ read bla; echo $bla
> dsa                                     <-- typed by me
> dsa
> 
> ok, works as expected, BUT:
> 
> $ unset bla
> $ echo dsa | read bla; echo $bla
> [empty line echo'd]
> 
> hmm.... doesn't work without a tty?
>  
> $ unset bla
> $ echo dsa > tmp.txt; read bla < tmp.txt; echo $bla
> dsa
> 
> eh..... why's that? Can't do it with a pipe, but can do from a file?
> Beats me...
> 
> Can anyone enlighten me as to why this behavior occurs?
> 
> --Stijn
> 

You're using /bin/sh isn't it? I don't know whether this is a bug or what,
simmilar with pdksh proble "echo bla | read ..."
But , if you do with zsh , you can get what you expect , as zsh treat
the pipe in a same proccess , not spawning another subshell.
Bash , sh , ksh have this sort of "bug" (correct me if i'm mistaken)

Under zsh,
$ echo lala | read x ; echo $x
lala
$ echo $x
lala
$ unset x
$ echo $x

$
(failed under sh, bash, ksh)


cheers
-- 


+----------------------------------------+
|          /\_____                       |
|         /     ./__                     |
|        /       __/ < I do understand.. |
|       /      ___/                      |
|      /      /                          |
| ^^^^^^^^^^^^^^^^^^^^^^                 |
|     *warf* *warf*                      |
|                                        |
+----------------------------------------+


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01020806275703.25931>