I noticed that the Solaris 10 Bourne shell, /bin/sh (as well as /sbin/sh ) expands the subshell when using indirectness ( < ). I tried a bunch of other Bourne-ish shells, including:
- 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 not one of them exhibits such behavior.
I am surprised that I have not bitten this before. For example, in more transparent shells (i.e., all of the 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 /bin/sh returns 0 because the assignment x=1 occurs in a subshell caused by indirectness: when the subshell completes this assignment. (If I remove </etc/passwd and read from stdin , then "1" comes out, as expected).
Is there any age-old reason that this "traditional" Solaris sh this property? Or is this a mistake?
source share