why doesn't this shell program work
BlandMA
mab at druxp.UUCP
Thu Mar 7 09:56:56 AEST 1985
Just to confuse matters a little more, ksh (the Korn shell) handles
this situation better than the Bourne shell, but still isn't perfect.
ima!johnl gave the following example:
a=one
for i in two three four
do
a=$i
done >plugh
echo $a
Using sh, the result is a=one. But ksh gives the desired result
of a=four. In the interest of efficiency, ksh tries not to fork extra
shells when possible, and this is apparently one of those situations.
Unfortunately, the following slightly modified version of the example,
using a pipe instead of a file for output, results in a=one with both
sh and ksh. Sigh.
a=one
for i in two three four
do
a=$i
done | cat
echo $a
Hey! Maybe we can add an option to "cat" to make this work! :-)
--
Alan Bland
{ihnp4, allegra}!druxp!mab
AT&T Information Systems Labs, Denver
More information about the Comp.unix
mailing list