On Sun, Aug 9, 2009 at 5:43 PM, Tony Mechelynck wrote:
>
> On 26/07/09 20:07, Matt Wozniski wrote:
>>
>> On Sun, Jul 26, 2009 at 11:34 AM, Efraim Yawitz<[email protected]>  
>> wrote:
>>>
>>> On Sun, Jul 26, 2009 at 6:20 PM, Gregory Margo<[email protected]>  wrote:
>>>>
>>>> No.  Shells in general (bash,dash,ksh,zsh,tcsh,csh) allow complete
>>>> removal of the environment variable.  Bourne-type shells use "unset"
>>>> and C-type shells use "unsetenv" commands.
>>>>
>>> OK, but why is that necessary?
>>
>> For programs that have different behavior depending on whether or not
>> a given environment variable exists - there are a great many programs
>> that fall into this category.  For instance...
>>
>> $ export PAGER='echo hello'
>> $ man man
>> hello
>> $ PAGER=
>> $ man man
>> <... implicitly paged as though by 'cat' ...>
>> $ unset PAGER
>> $ man man
>> <... implicitly paged through 'more' ...>
>>
>> So, you get different behavior for a non-empty environment variable,
>> an empty environment variable, and no environment variable.
>>
>> ~Matt
>
> I think we're up against a culture difference here. On Dos/Windows,
> setting an environmant variable to the empty string, e.g. by
>
>        SET SOMESTUFF=
>
> actually removes it, and to test if it exists, you check it against the
> empty sring, e.g;
>
>        IF x%SOMESTUFF% == x GOTO SOMESTUFFERROR
>        GOTO SOMESTUFFON
>        :SOMESTUFFERROR
>        ECHO SOMESTUFF undefined
>        GOTO FINISH
>        :SOMESTUFFON
>        ...
>        ...
>        :FINISH
>
> On Unix, it's not the same: you can set an environment variable
> explicitly to the empty string, e.g. (with bash)
>
>        export SOMESTUFF=''
>
> and that's not the same as having it unset.

That's not really a culture difference, afaics.  It's not uncommon to
see something like

    if [ "x$var" = x ]; then
      ...
    fi

in shell scripts on Unix, even though there is a distinction between
empty environment variables and nonexistent ones.  The same
distinction exists on Windows as well, even if it isn't exposed by the
batch scripting language.  The only reason code checking if a variable
expands to the empty string is idiomatic is because it's common to
want to treat empty and nonexistent variables the same way, not
because it's impossible to distinguish them.

~Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to