read unter RedHat AS
Achim Dreyer
adreyer at math.uni-paderborn.de
Thu Aug 14 02:43:01 CEST 2003
On Thu, 14 Aug 2003, Achim Dreyer wrote:
> On Wed, 13 Aug 2003, Michael Schneider wrote:
> > On Wed, 13 Aug 2003 21:24:02 +0200, Jan-Benedict Glaw wrote
> > > echo blah fasel | while read i j; do
> > > # Hier sind die Variablen gesetzt
> > > echo $i
> > > echo $j
> > > done
> > > # Ab hier nicht mehr
> >
> > jetzt wo du es sagst ..
> > mist dann muss ich alles umbauen ;-(
[..]
> .. in der alten Original Bourne Shell ging das auch noch anders (über
> umbiegen von filedescriptoren), aber bei der bash muß man immer
> filedescriptoren an dateien hängen.
see FAQ of comp.unix.shell (Ted Timar), section 3.8:
--snip--
In historic (and P1003.2 conformant) implementations you can use
the following `trick' to get around the redirection problem:
foo=bar
# make file descriptor 9 a duplicate of file descriptor 0 (stdin);
# then connect stdin to /etc/passwd; the original stdin is now
# `remembered' in file descriptor 9; see dup(2) and sh(1)
exec 9<&0 < /etc/passwd
while read line
do
# do something with $line
foo=bletch
done
# make stdin a duplicate of file descriptor 9, i.e. reconnect
# it to the original stdin; then close file descriptor 9
exec 0<&9 9<&-
echo "foo is now: $foo"
This should always print ``foo is now: bletch''.
--snip--
Regards,
Achim Dreyer
--
A. Dreyer, Senior SysAdmin (UNIX&Network) / Internet Security Consultant
More information about the Linux
mailing list