Bourne shell oddity
Maarten Litmaath
maart at cs.vu.nl
Thu Aug 9 01:34:27 AEST 1990
In article <9008071535.AA01487 at stc06.CTD.ORNL.GOV>,
de5 at STC06.CTD.ORNL.GOV (SILL D E) writes:
)...
)#!/bin/sh
)foo=bar
)while true
)do
) if [ $foo = bar ]
) then
) foo=baz
) echo foo=${foo}
) break
) fi
)done </dev/null
)echo foo=${foo}
Most current implementations: foo=bar.
POSIX requires: foo=baz.
)...
)Another Question: Is there a simple workaround, preferably something
)more elegant than passing values in files?
foo=bar
# dup(2) file descriptor 0 to fd 9,
# then connect fd 0 (== stdin) to /dev/null
exec 9<&0 < /dev/null
while true
do
...
done
# dup() fd 9 back to fd 0,
# i.e. reconnect fd 0 to the original stdin, then close fd 9
exec 0<&9 9<&-
echo foo=$foo
--
"UNIX was never designed to keep people from doing stupid things, because
that policy would also keep them from doing clever things." (Doug Gwyn)
More information about the Comp.unix.questions
mailing list