A)
first I run export a=1&&echo $a
in linux terminal and I get 1.
[root@ip-172-31-16-92 ec2-user]# export a=1&&echo $a
1
B)
But when I run sh -c "export a=2&&echo $a"
and I still get 1 instead of 2.
[root@ip-172-31-16-92 ec2-user]# sh -c "export a=2&&echo $a"
1
What happend? If sh -c "export a=2&&echo $a"
itself is a child process of the terminal,it should have its own environment, first it should make a copy of his father environment,so a=1,but when it execute export a=2
,environment a should be set to 2,then echo $a
should be 2.But it returns 1,what happend?