nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] Environment variables - with or without $?

2017-03-23 16:25:17
    Date:        Thu, 23 Mar 2017 13:46:57 -0400
    From:        valdis(_dot_)kletnieks(_at_)vt(_dot_)edu
    Message-ID:  
<7620(_dot_)1490291217(_at_)turing-police(_dot_)cc(_dot_)vt(_dot_)edu>


  | Some shells will auto-export certain recognized shell variable such
  | as $TERM or $PATH or $HOME and export the value as an environment variable

That is not the way it works.   The shell exports any variable marked
for export (using the "export" command).   Variables that the shell
imports from the environment are marked for export automatically.

If you want to verify this just
        unset TERM  ; # delete TERM from the shell completely
        TERM=xterm      ;  # create a new variable called TERM (any value you 
like)
        env | grep TERM
you'll see that the new TERM variable, which was not imported from
the environment, and which hasn't been marked for export, is not exported)

You can try that with any of what you consider "recognised" variables.

So anything which came from the environment when the shell starts is
automatically exported to sub-processes, as is anything added using "export"
and also any variable set in "assignment words" preceding the command:
        X=foo command
sets X, and exports it, for command only (provided command is a real
binary, if it is a sh function different rules apply, for no good reason
at all.)

And as to "$FOO" from a later message - there is a strict syntax for
shell variable names - they start with a letter or underscore, and are
entirely letters, digits, and underscores (if you treat underscore as
a letter, that is basicly a fortran variable name...)   The syntax is
required or the shell parser would not work as it should.

You can stick anything you like in the environment, but strictly the
shell should not treat it as a variable unless it is of the form "name=..."
(where 'name' is a valid shell variable name.)

Bash lets you get away with all kinds of cruft (but probably not a
variable that starts with a '$'), but you should not rely upon any of that.

kre


_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
https://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>