[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
piped functions cannot set variables
From: |
Andrew Robb |
Subject: |
piped functions cannot set variables |
Date: |
Thu, 19 Dec 2002 12:22:17 +0000 |
under sh and ksh the following code echos 1
fred() { A=1; } ; unset A ; echo hello | fred ; echo $A
this does not work in bash.
However, if I do not use a pipe, it echos 1, as does sh and ksh
fred() { A=1; } ; unset A ; fred ; echo $A
I wan't to use a shell function as a filter to read the output from
another program into arrays.
This works in ksh but not bash.
It looks like I could use a named pipe to make it work, but this is
clumsy.
fred() { A=1; } ; unset A ; rm -f fifo ; mkfifo fifo ; echo hello >
fifo & fred < fifo ; rm -f fifo ; echo A
(of course, this example generated a SIGPIPE in echo)
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
- piped functions cannot set variables,
Andrew Robb <=