On Sat, Jul 20, 2024 at 06:30:42 +0800, pyh@gmx.it wrote:
On 2024-07-20 06:25, Greg Wooledge wrote:
> >
> > I can not clearly understand for this statement. what's "future shell
> > commands"? can you show an example?
>
> hobbit:~$ unset -v VAR
> hobbit:~$ VAR=bar; ./a.sh
> I am a.sh, and inside me, VAR=<>.
> hobbit:~$ echo "VAR=<$VAR>"
> VAR=<bar>
OK I know that. $VAR can be seen by future shell command in this
session, but cannot be seen by a sub-shell such as a.sh.
a.sh is NOT a subshell. That's really super important.
a.sh is a NON-subshell child process.
In an actual subshell, you *would* see the variable, because subshells
inherit regular variables as well as environment variables.
hobbit:~$ unset -v VAR
hobbit:~$ VAR=foo; (echo "I am a subshell, and VAR=<$VAR>")
I am a subshell, and VAR=<foo>
hobbit:~$ ./a.sh
I am a.sh, and inside me, VAR=<>.
https://mywiki.wooledge.org/SubShell