Re: Shell scripts: variable assignment within read loops

2008-08-21 Thread Jan Grant
On Sun, 17 Aug 2008, David Wolfskill wrote: [snipped] will assign to foo the value of the bar variable form the last record read (in FreeBSD 6.3-STABLE, at least), the following fails to do so: foo= cat $filename | while read bar ... ; do ... foo=$bar

Re: Shell scripts: variable assignment within read loops

2008-08-19 Thread Oliver Fromme
David Wolfskill wrote: I am writing a (Bourne) shell script that is intended (among other things) to obtain information from a command, such as: netstat -nibd -f inet by reading and parsing the output. However, the obvious (to me) approach of piping the output of the

Re: Shell scripts: variable assignment within read loops

2008-08-19 Thread CyberLeo Kitsana
David Wolfskill wrote: foo= cat $filename | while read bar ... ; do ... foo=$bar ... done echo $foo A trick I've used to great advantage in bourne shell and bash for passing multiple variables back is to produce small snippets of shell script

Re: Shell scripts: variable assignment within read loops

2008-08-18 Thread Polytropon
As I thought while reading your message, awk seems to be a good solution. Just a note: On Mon, 18 Aug 2008 06:29:03 +0300, Giorgos Keramidas [EMAIL PROTECTED] wrote: Would you be ok with an awk(1) script instead of /bin/sh? It tends to be nicer for this sort of thing, i.e.: [...] $

Re: Shell scripts: variable assignment within read loops

2008-08-18 Thread Giorgos Keramidas
On Mon, 18 Aug 2008 14:33:05 +0200, Polytropon [EMAIL PROTECTED] wrote: As I thought while reading your message, awk seems to be a good solution. Just a note: On Mon, 18 Aug 2008 06:29:03 +0300, Giorgos Keramidas [EMAIL PROTECTED] wrote: Would you be ok with an awk(1) script instead of

Shell scripts: variable assignment within read loops

2008-08-17 Thread David Wolfskill
I am writing a (Bourne) shell script that is intended (among other things) to obtain information from a command, such as: netstat -nibd -f inet by reading and parsing the output. However, the obvious (to me) approach of piping the output of the command to the standard input of a while

Re: Shell scripts: variable assignment within read loops

2008-08-17 Thread Giorgos Keramidas
On Sun, 17 Aug 2008 18:33:28 -0700, David Wolfskill [EMAIL PROTECTED] wrote: I am writing a (Bourne) shell script that is intended (among other things) to obtain information from a command, such as: netstat -nibd -f inet by reading and parsing the output. However, the obvious (to me)

Re: Shell scripts: variable assignment within read loops

2008-08-17 Thread David Wolfskill
On Mon, Aug 18, 2008 at 06:29:03AM +0300, Giorgos Keramidas wrote: ... You are right that feeding data to a looping construct through a pipe may run in a subshell. The ``Single UNIX Specification'' says Ah; thanks for the confirmation. ... What I usually do in similar shell scripts