This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Unusual environemtal variables


Eric Blake:
> That is inherently non-portable.  POSIX states that "Other characters may
> be permitted by an implementation; applications shall tolerate the
> presence of such names," but does not require applications to be able to
> create such names.

Right.

Ehud Karni:
> This behavior (accepting names of only ASCII Alpha and _) is a bash self
> imposed limitation. If you use csh (or tcsh) names with other characters
> are supported too.

Somewhat overstated.

None of the shells I know of will let you set a shell
variable/parameter whose name doesn't match the standard ASCII
identifier pattern (initial letter or underscore followed by letters,
underscore, or digits):

bash$ @foo=bar
bash: @foo=bar: command not found

bash$ export @foo=bar
bash: export: `@foo=bar': not a valid identifier

tcsh% set @foo=bar
set: Variable name must begin with a letter.

Since in sh/bash/ksh, the only way to set an environment variable is
to first set a shell variable and then "export" it into the
environment, the above restriction on shell variables becomes a
restriction on environment variables, too.  Whereas in *csh, shell
variables and environment variables are set via different commands, so
the restriction on shell variables doesn't extend to the environment:

tcsh% setenv @FOO bar
tcsh%

Even in the *csh shells, however, environment variables are still
expanded via the same mechanism as shell variables, so the value of
one with a non-portable name is not accessible directly:

tcsh% echo $@FOO
Illegal variable name.

tcsh% echo ${@FOO}
Illegal variable name.

You have to use indirection, e.g.:

tcsh% setenv | awk -F= '($1=="@FOO") {print $2}'
bar

At least ash and bash leave variables with non-portable names in the
environment to pass on to child processes; it looks like zsh and ksh
(both AT&T and PD versions) strip them from the environment entirely:

env @FOO=bar ksh
ksh$ env | grep @FOO
ksh$

None of the foregoing is unique to Cygwin, however.  The intersection
is that there seem to be Windows applications which expect to inherit
environment variables with non-POSIX names, and Cygwin users such as
Steve who wish to launch such programs from the Cygwin environment.
The logical solution there is to do as Eric suggested and use env,
although if it's a simple script (or one you consider worth the
porting effort) you could also rewrite it in csh instead.

--
Mark J. Reed <markjreed@gmail.com>

--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]