Friday, October 16, 2015

system command takes a different environment variable from current shell?

Hi,
I have a login tcsh which originally has this environment variable c set as “/volume/current”:
<<<
601% env | grep "SHELL\|current"
SHELL=tcsh
c=/volume/current
XTERM_SHELL=/bin/tcsh
>>>
 
And in vim, when I do 1) echo $c, and 2) let x = system(“echo $c”); and then “echo x”, both shows “/volume/current”, which is expected;
 
Then inside this shell I set this variable to another value:
<<<
603% setenv c /volumeNEW/current
604% env | grep "SHELL\|current"
SHELL=tcsh
c=/volumeNEW/current
XTERM_SHELL=/bin/tcsh
>>>
 
And now in in vim, when I do “echo $c” it shows the new value “/volumeNEW/current”, but when I use the above mentioned 2nd way, it shows the old value “/volume/current”. Is it supposed to show the new value?
 
Am I wrong about how system() is supposed to pick up environment variable? Or there is a bug here?
 
Thanks.
--Karl
 

No comments: