From owner-freebsd-questions Wed Feb 7 14:15:20 2001 Delivered-To: freebsd-questions@freebsd.org Received: from FreeBSD.mine.nu (unknown [203.106.71.238]) by hub.freebsd.org (Postfix) with ESMTP id 67A1937B491 for ; Wed, 7 Feb 2001 14:14:58 -0800 (PST) Received: from FreeBSD.mine.nu (-@localhost [127.0.0.1]) by FreeBSD.mine.nu (8.8.8/8.8.8) with SMTP id GAA01214; Thu, 8 Feb 2001 06:27:57 +0800 (MYT) (envelope-from skywizard@time.net.my) From: Ariff Abdullah Reply-To: skywizard@time.net.my Organization: FreeBSD 2.2.8-RELEASE To: Stijn Hoop Subject: Re: read in /bin/sh & pipes [was Re: sed & awk help...?!] Date: Thu, 8 Feb 2001 06:20:50 +0800 X-Mailer: KMail [version 1.0.28] Content-Type: text/plain References: <054F7DAA9E54D311AD090008C74CE9BD01F1E94E@exchange.panasonicfa.com> <01020804390900.25931@FreeBSD.mine.nu> <20010207225303.B12534@pcwin002.win.tue.nl> In-Reply-To: <20010207225303.B12534@pcwin002.win.tue.nl> Cc: freebsd-questions@FreeBSD.org MIME-Version: 1.0 Message-Id: <01020806275703.25931@FreeBSD.mine.nu> Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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