but %ENV is magical
%ENV appears to be magical only under shells where the lookup and expansion of environmental variables is a case-insensitve operation.
$ set comspec
ComSpec=C:\WINDOWS\system32\cmd.exe
$ echo %comspec%
C:\WINDOWS\system32\cmd.exe
$ echo %COMSPEC%
C:\WINDOWS\system32\cmd.exe
$ perl -le "print 'comspec : ', $ENV{comspec}"
comspec : C:\WINDOWS\system32\cmd.exe
$ perl -le "print 'COMSPEC : ', $ENV{COMSPEC}"
COMSPEC : C:\WINDOWS\system32\cmd.exe
On systems (shells rather) where there is a distinction between the case-sensitivity of Env. Vars, %ENV behaves rather normally like a hash should.
$ set | grep -i ^shell
shell /bin/tcsh
$ echo $shell
/bin/tcsh
$ echo $SHELL
$ perl -le 'print "shell : ", $ENV{shell}'
shell :
$ perl -le 'print "SHELL : ", $ENV{SHELL}'
SHELL : /bin/bash
It's likely %ENV is tied (I am guessing) or has mechanism similar to tie associated with it to pass lookups to an underlying system call. It should be noted that not all environmental varaibles are populated into %ENV and in other cases, the values of %ENV contradict those of the shell (as shown above). Don't rely too heavily on information or its validity presented to you in %ENV;
There is a difference between %ENV and Win32::ExpandEnvironmentStrings.
%ENV holds literals (just like the shell, in most cases atleast), Win32::ExpandEnvironmentStrings() tests the expansion of a literal in the win32 environment and returns it after substituting values defined for the current user.
$ set var
var=%OS%
$ perl -MWin32 -e "print $ENV{var} .= ' evaled' , ' => ', Win32::Expa
+ndEnvironmentStrings($ENV{var})"
%OS% evaled => Windows_NT evaled
For the purposes of delayed expansion in the environment, Win32::ExpandEnvironmentStrings() then takes a literal string of the form !Foo! rather than %Foo%.
$ set var=Foo
$ set var
var=Foo
$ set var=Bar & perl -MWin32 -e "print Win32::ExpandEnvironmentStrings
+('%var%')"
Foo
$ set var
var=Bar
$ set var=Baz & perl -MWin32 -e "print Win32::ExpandEnvironmentStrings
+('!var!')"
Baz
$ set var
var=Baz
|