[Gllug] Bourne shell programming

Mike Brodbelt mike at coruscant.demon.co.uk
Sun Nov 19 03:24:07 UTC 2006


I've got an irritating shell problem, and as I only code shell when I
absolutely have to, I can't see a way round it right now.

I'm doing something like:-

grep root /etc/passwd | awk -F: '{print $1,$2,$3}' | while read x
do
	some stuff
done

That's not exactly it, but it illustrates what I'm attempting.

Now variables I set inside the loop vanish, as the pipe causes a
subshell to be spawned, so I can't set variables in the body of my loop
that are visible to the rest of the script. In the case of a file, I
could simply do "exec < myfile" to replace stdin, so I could use the
loop without a pipe, and thus not spawn a subshell.

How can I replace stdin with the output of my previous command? I need
to be able to read from the pipeline....

Thanks,

Mike
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list