1.5.9: Trouble with setting variables using 'read' in a script

2004-05-06 Thread Kevan Gelling
I'm having trouble setting variables using the 'read' command in bash. All of the following lines fail to set $var and return a blank line. - echo "text" | read var ; echo $var - cat file | read var ; echo $var - read var < file | echo $var I can get it work by explicitly declaring the fil

Re: 1.5.9: Trouble with setting variables using 'read' in a script

2004-05-06 Thread Andy Rushton
Kevan Gelling wrote: I'm having trouble setting variables using the 'read' command in bash. All of the following lines fail to set $var and return a blank line. - echo "text" | read var ; echo $var - cat file | read var ; echo $var - read var < file | echo $var The problem is that the pipelin

Re: 1.5.9: Trouble with setting variables using 'read' in a script

2004-05-06 Thread Brian Dessent
Kevan Gelling wrote: > All of the following lines fail to set $var and return a blank line. > - echo "text" | read var ; echo $var > - cat file | read var ; echo $var > - read var < file | echo $var The other reply by Andy R is spot on, you can't modify the current environment from a subshe

cont'd - RE: 1.5.9: Trouble with setting variables using 'read' in a script

2004-05-06 Thread Jan Schormann
(Please excuse the unfinished last mail, I hit "Ctrl-Enter" by accident.) > - echo "text" | read var ; echo $var > - cat file | read var ; echo $var > - read var < file | echo $var .. continuing from last time, all of these won't work because you're always creating a new subshell. Try r

RE: 'read' and pipes, was: 1.5.9: Trouble with setting variables using 'read' in a script

2004-05-06 Thread Jan Schormann
> Another related quirk, is that variables set within > 'while read' loops lose > their values once the loop ends. The following example > displays "text text" > within the loop and blank line outside. > - echo "text" |\ > while read > do > foo=$REPLY ; bar="text" > echo $foo