www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/08/21/18:38:49

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs
Date: Sat, 21 Aug 2004 18:38:42 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: "Buchbinder, Barry (NIH/NIAID)" <BBuchbinder AT niaid DOT nih DOT gov>
cc: cygwin AT cygwin DOT com
Subject: RE: environment variable name converted to upper case
In-Reply-To: <F76C9B2DA2FC4C4CA0A18E288BBCBCF708217C86@nihexchange24.nih.gov>
Message-ID: <Pine.GSO.4.61.0408211412350.19750@slinky.cs.nyu.edu>
References: <F76C9B2DA2FC4C4CA0A18E288BBCBCF708217C86 AT nihexchange24 DOT nih DOT gov>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.39

On Sat, 21 Aug 2004, Buchbinder, Barry (NIH/NIAID) wrote:

> To expand on what Chris wrote, this is caused by the fact that in
> command.com (but not cmd.exe as supplied by XP - I don't know about earlier
> versions of cmd.exe) all user-setable Windows environmental variable are
> uppercase.

That's not quite true.  cmd.exe under XP and 2k preserves the case of 
variable names, but accesses to the variables are still case-insensitive.

> [snip]
> Now
> 	> echo %ZZZ%
> 	aaa
> 	> echo %zzz%
> 	aaa

The same happens under cmd.exe.  Try also "echo %zZz%". :-)

> Note that in some versions of Windows, Windows itself sets a variable with a
> lowercase name so that it would be impossible for the user to set it.
> Windows 98se has
> 	windir=C:\WINDOWS
> I can
> 	> set windir=xxx
> and find that
> 	windir=C:\WINDOWS
> is unchanged but I now have a variable
> 	WINDIR=xxx
> But it cannot be accessed as seen by
> 	> echo %windir%
> 	C:\WINDOWS
> 	> echo %WINDIR%
> 	C:\WINDOWS

This is expected, since, as I said before, variable names are 
case-insensitive in %..% accesses.  They apparently aren't in the set 
command, so set will append a new entry to the end of the environment 
block with the lowercase name.  Upon searching, however (and the 
environment is searched linearly, no fancy stuff like hashing) the 
uppercase version is found first (since it was set earlier).

> My guess is that on XP, cygwin.bat runs under command.com (which is
> available under all versions of Windows), not cmd.exe (provided only with
> NT/2k/XP).

FYI, there's a clone of cmd.exe for Win9x/ME.  That won't help much, 
however, since even in cmd.exe variable accesses are case-insensitive.

> As Chris said, the easiest way to set the variable is in the shell.

True.

> Under NT/2k/XP, you might get the behavior you want by changing 
> cygwin.bat to cygwin.cmd, or running bash directly (if the variable is 
> set in the global environment).

Not true.  The behavior of changing the case of the variable names is 
coming from Windows, namely the GetEnvironmentStrings() call.  I just 
tried a small application from MSDN that just calls 
GetEnvironmentStrings() and prints out the result[*].  All of the variable 
names that come from the Windows environment were uppercased.

> You'll have to experiment.  For the record, under Windows 9x/Me, setting 
> the environmental variable in the shell is probably the only way to do 
> it.

Not quite true.  Setting the variable in the shell is *the* only way to do 
it, independent of the OS.
HTH,
	Igor

[*] Example 3 from 
<http://msdn.microsoft.com/library/en-us/dllproc/base/changing_environment_variables.asp>

> -----Original Message-----
> From: Christopher Faylor [mailto:cgf-no-personal-reply-please AT cygwin DOT com] 
> Sent: Saturday, August 21, 2004 12:21 PM
> To: cygwin AT cygwin DOT com
> Subject: Re: environment variable name converted to upper case
> 
> On Sat, Aug 21, 2004 at 09:30:53PM +0530, Koduru, Seshasai wrote:
> >An environment variable name defined in windows environment with 
> >lowercase is converted to uppercase by cygwin environment.
> >
> >Because of this behavior the shell scripts are not recognizing 
> >$lowercase variable. Is this the regular expected behavior?
> 
> Yes.
> 
> >Is there any way to get the case preserved?
> 
> Don't set the environment variable at the windows level.  Set it in the
> shell prior to running the program.
> 
> If that isn't adequate, then there probably isn't any way to do what you
> want.

-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019