Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from pipe (Korn Shell)

Status
Not open for further replies.

SteveR77

Programmer
Sep 18, 2000
813
US
I am attempting to remember what the issue is with piping data and attempting to use read to do assignment to variables.

For example -

print a b c | read one two three

Given that the pipe should be sending a b c as Stdin to the read it seems that one should equal a, etc.

I know I am forgetting something in the case and thank all for their assistance in advance.


Steve
 
man read
man ksh (pay attention to IFS)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks PHV but reading the manual pages is not the solution.


The issue is with the built-in read under certain versions of Linux. In this case 7.1 of RedHat.

The built-in read assumes a console device for input of stdin which in effects over rides what the pipe is attempting to do.

The assignment of print a b c | read one two three

is valid but the results you will get will depend upon how the shell is viewing the stdin device.

The work around to this issue is to redirect the data steam to a file then use it as the input to the read.

For example -

print a b c > inputfile

read one two three < inputfile


Thanks again for the help.


Steve

 
I can't figure out why one time (with pipe) the read builtin assumes the console as stdin and another time (< inputfile) it honors the shell redirection.
 
PHV,

It's madding and why I couldn't remember. Some Bash shells are OK and some aren't. Some Korn shells are OK and others aren't.

It's one of those things that I will try to bear in mind for the future.

Thanks once again.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top