On 25/07/09 22:45, Gregory Margo wrote:
>
> On Wed, Jul 22, 2009 at 10:16:34PM -0500, _sc_ wrote:
>>
>> On Wednesday 22 July 2009 9:53 pm, Chris Sutcliffe wrote:
>>>
>>>>> Is it possible to clear an environment variable via vim script? I've
>>>>> tried:
>>>>>
>>>>> let $MvVar =
>>>>>
>>>>> but vim complains. I've also tried:
>>>>>
>>>>> unlet $MyVar
>>>>>
>>>>> with no success.
>>>>
>>>> did you define MyVar with a dollar sign? or are you suffering from
>>>> iknowtoomanylanguagesitus?
>>>
>>> It's an environmental variable that exists outside of Vim. What I
>>> would like to do is clear it temporarily, call and external program,
>>> and restore it after calling the external program. Something like:
>>>
>>> let save_MyVar = $MyVar
>>> unlet $MyVar
>>> exe '!someprog'
>>> let $MyVar = save_MyVar
>>>
>>> would be ideal, but the 'unlet' is the problem.
>>
>> apparently i didn't have enough coffee this morning -- you did
>> indeed say it was an environment variable
>>
>> since let and unlet are vim script commands, they affect variables
>> inside the script, not the environment
>>
>> because '!' creates a new shell to run someprog, even if you
>> execute '!export MyVar=' your next '!someprog' is going to get yet
>> another shell to run in, and MyVar will be in its defined state
>>
>> one of the oldest Laws of Unix is no script can modify its parent's
>> environment
>>
>> my recommendation is to write a new shell script that undefines
>> MyVar and triggers someprog so vim doesn't have to care about shell
>> environment variables -- or tweak someprog so it doesn't use MyVar
>>
>> sc
>
> I don't quite agree. I don't think the orignal post is asking to modify
> the parent's environment, just the spawned children's.
>
> Although vim provides a mechanism to add environment variables,
> it does not seem to provide any mechanism to remove environment
> variables, whether or not it was created within vim. This is an
> omission IMHO.
>
> One may create an entirely new environment variable, that is passed to
> children, with:
> :let $NEWVAR = "foobar"
> but there us no way to delete that environment variable. You can assign
> a blank string to it,
> :let $NEWVAR = ""
> but that still leaves the variable in the environment.
>
> IMHO,
> :unlet $NEWVAR
> should remove that environment variable completely. But it comes up as
> error E488.
>
I haven't read the whole thread yet, but what about
:!(unset MYVAR && someprog)
in bash or similar? (Wouldn't work in cmd.exe, I suppose.)
Best regards,
Tony.
--
The best way to make a fire with two sticks is to make sure one of them
is a match.
-- Will Rogers
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---