[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

From: Robert Elz
Subject: Re: [Nmh-workers] Environment variables - with or without $?
Date: Fri, 24 Mar 2017 04:24:39 +0700

    Date:        Thu, 23 Mar 2017 13:46:57 -0400
    From:        address@hidden
    Message-ID:  <address@hidden>

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]