The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AIX 5.3 - There is no process to read data written to a pipe vigsgb UNIX for Advanced & Expert Users 6 05-22-2009 05:59 AM
pipe read and write with many forked children steveneliuk High Level Programming 5 05-23-2007 07:03 AM
Problem in read() from a pipe JDS High Level Programming 2 10-13-2006 11:19 AM
Pipe Problem vivivo2000 High Level Programming 2 01-11-2006 04:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2005
relyveld relyveld is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 6
read after pipe problem OSX10.4

I use read often in scripts to filter the right part into a variable like:

$ print "abc cde efg" | read k l ; print "k=$k, l=$l"
k=, l=

This works on linux and unix versions I work with. On OSX 10.4 this
doesn't work. I found a workaround but would like to know
why the original line fails. And I don't like the
$ print "abc cde efg" |& read -p k l ; print "k=$k, l=$l"
[1] 11299
k=abc, l=cde efg


Greetings, William
  #2 (permalink)  
Old 07-06-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
Your ksh version has a bug. The original is the right syntax. "read -p" should fail. It's for reading from a co-process.
  #3 (permalink)  
Old 07-06-2005
r2007's Avatar
r2007 r2007 is offline
Registered User
  
 

Join Date: Jun 2005
Location: China
Posts: 73
try:

Code:
print "abc cde efg" | { read k l ; print "k=$k, l=$l" ; }

  #4 (permalink)  
Old 07-07-2005
relyveld relyveld is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 6
Thanks for the replies, Perderabo and R2007.

Perderabo, what is strange is that when I start a different terminal, or
a different shell, they all behave the same. I tried bash, tcsh, csh and sh.
I expect it has to do with the OSX darwin or BSD system. Also commands
like ls and tar are different. It took me some time to get colors enabled
and app-defaults installed right for keybord shortcuts. The csh results:

$ csh
[d213-102-60-49:~] relyveld% echo "abc cde efg" | read k l ; echo "k=$k, l=$l"
csh: k: Undefined variable.

Finaly, I tried zsh and this one works! But I don't know zsh and all my
scripts are ksh based..

zsh:
d213-102-60-49% zsh
which read
read: shell built-in command
d213-102-60-49% exit


ksh:
$ which read
/usr/bin/read


$ zsh
d213-102-60-49% echo "abc cde efg" | read k l ; echo "k=$k, l=$l"
k=abc, l=cde efg


Test result (ksh):

$ print "abc cde efg" | { read k l ; print "k=$k, l=$l" ; }
k=, l=


Greetings, William.
  #5 (permalink)  
Old 07-07-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
I would not expect this to work with sh, csh, tcsh, or bash.

In ksh, do "whence -v read". read has to be a built-in.

zsh has almost everything that ksh and tcsh has. Many ksh scripts should work on zsh. Or so I'm told... I have never used it.
  #6 (permalink)  
Old 07-07-2005
r2007's Avatar
r2007 r2007 is offline
Registered User
  
 

Join Date: Jun 2005
Location: China
Posts: 73
Quote:
Test result (ksh):

$ print "abc cde efg" | { read k l ; print "k=$k, l=$l" ; }
k=, l=
I am in puzzle about this. Can somebody tell me why?
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0