Saturday, October 17, 2015

Re: system command takes a different environment variable from current shell?

2015-10-18 0:51 GMT+03:00 Nikolay Pavlov <zyx.vim@gmail.com>:
> 2015-10-16 19:27 GMT+03:00 Karl (Xiangrong) Cai <xcai@juniper.net>:
>> 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?
>
> You need to refer to your shell documentation. The answer to this
> question depends on which configuration files shell is sourcing in
> different cases. In case of system it is run using something like
> `&shell . ' ' .&shellcmdflag . ' ' . shellescape("echo $c")` (use
> `strace -e execve -f` to trace what is actually run).
>
> I think that system() is picking up your environment variable, but
> shell is overwriting it later with the "default" value sourced from
> configuration. To confirm revert to safer options (POSIX shell, which
> does not source tcsh configuration, and hopefully no its own: at least
> bash aliased to sh does not source any configuration with `sh -c 'echo
> true'` as confirmed by strace) and repeat:
>
> set shell=/bin/sh shellcmdflag=-c shellquote= shellxquote=
> echo system('echo $c')
>
> .

And yes, unless it is shell that is responsible for overwriting
environment variable, it is a bug. But this part of Vim code is highly
stable and Vim bug is very unlikely. If it is Vim bug it will be seen
with any shell.

>
>>
>> Am I wrong about how system() is supposed to pick up environment variable?
>> Or there is a bug here?
>>
>> Thanks.
>> --Karl
>>
>>
>> --
>> --
>> You received this message from the "vim_use" maillist.
>> Do not top-post! Type your reply below the text you are replying to.
>> For more information, visit http://www.vim.org/maillist.php
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "vim_use" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to vim_use+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: