/bin/sh => STDIN & functions, var scope messing

Reid Linnemann linnemannr at gmail.com
Mon May 27 19:58:29 UTC 2013


from SH(1)

"Note that unlike some other shells, sh executes each process in a pipe-
     line with more than one command in a subshell environment and as a
child
     of the sh process."

I'm taking this to mean that redirecting to sh_f has sh_f execute in a
subshell in which global_scope_var changes, but the original shell's copy
is uncahnged.



On Mon, May 27, 2013 at 2:42 PM, <rank1seeker at gmail.com> wrote:

> 9.1-RELEASE-p3
> ---------------
> #!/bin/sh
>
> sh_f ()
> {
>     global_scope_var=7463457
> }
>
> yes | sh_f
> echo "$global_scope_var"
>
> echo '
> Now without /usr/bin/yes (maybe it is STDIN issue, instead) ?!?
> '
>
> sh_f
> echo "$global_scope_var"
> ---------------
>
>
> Domagoj Smolčić
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"


More information about the freebsd-hackers mailing list