On Sat, Jul 20, 2024 at 06:17:46 +0800, p...@gmx.it wrote:
> $ VAR=foo ./a.sh
> i can see VAR=foo

I don't know what "see" means here.

hobbit:~$ cat a.sh
#!/bin/sh
echo "I am a.sh, and inside me, VAR=<$VAR>."
hobbit:~$ unset -v VAR
hobbit:~$ VAR=foo ./a.sh
I am a.sh, and inside me, VAR=<foo>.
hobbit:~$ echo "VAR=<$VAR>"
VAR=<>

VAR is defined in the environment of a.sh but NOT in the calling shell.

> >     What's the difference between these two commands?
> >         VAR3=foo ./a.sh
> >         VAR3=bar; ./a.sh
> > 
> > In the first command, VAR3 is placed in the environment of the command
> > being executed.  ./a.sh will see it.  VAR3 will not survive beyond
> > this command.  It will be discarded, and future commands will not be
> > aware it ever existed.
> > 
> > In the second command, VAR3 is created as a regular variable in the
> > current shell, but not exported to the environment.  It will NOT be
> > seen by ./a.sh, but it WILL be seen by future shell commands within
> > this session.
> 
> 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>

Reply via email to