public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Mark J. Reed" <markjreed@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Unusual environemtal variables
Date: Mon, 22 Dec 2008 15:20:00 -0000	[thread overview]
Message-ID: <f60fe000812220719g77be6974nba60489c69036854@mail.gmail.com> (raw)
In-Reply-To: <200812211606.mBLG6LX2014401@beta.mvs.co.il>

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/

      parent reply	other threads:[~2008-12-22 15:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-19  9:23 Steve Rainbird
2008-12-19 13:46 ` Eric Blake
2008-12-21 16:07   ` Ehud Karni
2008-12-21 19:44     ` Steve Rainbird
2008-12-22 15:20     ` Mark J. Reed [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f60fe000812220719g77be6974nba60489c69036854@mail.gmail.com \
    --to=markjreed@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).