FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 01-04-2010, 06:10 PM
Foss User
 
Default read command not reading from pipe. why?

I see that the read command stores input entered only on the console
into the variables. Example:

$ read a
foo
$ echo $a
foo

But when I don't enter input on the console by keyboard, but pipe it
into the standard input of read, I am unable to store the input into
the variable.

$ echo bar | read a
$ echo $a
foo

However, the help of read says this:

$ help read
read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-p
prompt] [-t timeout] [-u fd] [name ...]
Read a line from the standard input and split it into fields.

So, why is it not reading the line from standard input when input is
passed to it using a pipe?


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-04-2010, 06:34 PM
Teemu Likonen
 
Default read command not reading from pipe. why?

On 2010-01-05 00:40 (+0530), Foss User wrote:

> But when I don't enter input on the console by keyboard, but pipe it
> into the standard input of read, I am unable to store the input into
> the variable.
>
> $ echo bar | read a
> $ echo $a
> foo

Because of piping command "read a" is executed in another process so the
variable "a" has different binding there. It won't affect its mother
process in which you later executed the "echo $a" command. Here's
another example:

$ a=foo
$ echo bar | { read a; echo $a; }
bar
$ echo $a
foo


--
Feel free to Cc me your replies
if you want to make sure I'll notice them.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 09:33 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org