I have noticed that Solaris 10's Bourne shell, /bin/sh
(and also /sbin/sh
) forks a subshell when using indirection (<
). I have tried a pile of other Bourne-ish shells, including:
- The POSIX
/usr/xpg4/bin/sh
shell on Solaris 10 /bin/bash
,/bin/ksh
on Solaris 10/bin/sh
on AIX 5/bin/sh
on Debian Linux 5
and none of these exhibit this behavior.
I'm amazed I haven't been bitten by this before. For example, in the saner shells (ie all those listed above) the following script outputs "1":
$ cat foo
#!/bin/sh
x=0
while read y ; do
x=1
done </etc/passwd
echo $x
$ ./foo
0
$
Solaris 10's /bin/sh
returns 0 because the assignment x=1
occurs in the subshell caused by the indirection: when the subshell exits that assignment is lost. (If I remove </etc/passwd
and read from stdin
instead then "1" is output, as expected).
Is there some age-old reason that the "traditional" Solaris sh
has this property? Or is this a bug?