Just like Perl has private variables (my $x
) and environment variables ($ENV{Y}
), so does the shell.
$ perl <<'.'
my $x = "x";
$ENV{Y}="Y";
system 'echo "<$x> <$Y>"';
.
<> <Y>
$ sh <<'.'
x=x
export Y=Y
perl -le'print "<$x> <$ENV{Y}>";'
.
<> <Y>
$ csh <<'.'
set x x
setenv Y Y
perl -le'print "<$x> <$ENV{Y}>";'
.
<> <Y>
Having support for private variables is a good thing, not a strange thing.
In your example, $HOST
is an environment variable (uppercase by convention), while $env
is a private variable (lowercase by convention).
sh
and bash
These shells use the same mechanism to assign to private variables and environment variables.
To create an environment variable, one promotes a private variable to an environment using export
.
VAR=val
export VAR
perl -e'...$ENV{VAR}...'
or
export VAR
VAR=val
perl -e'...$ENV{VAR}...'
The promotion and assignment can be combined.
export VAR=val
perl -e'...$ENV{VAR}...'
The above approaches change the environment for the shell, and all subsequent children it creates. The following approach can be used to change a specific child's environment:
VAR=val perl -e'...$ENV{VAR}...'
That approach can also be used to effectively promote a private variable:
var=val
VAR="$var" perl -e'...$ENV{VAR}...'
csh
and tcsh
These shells use different syntax for setting private variables and environment variables.
To set a private variable, one uses set
.
set var val
To set an environment variable, one uses setenv
.
setenv VAR val
perl -e'...$ENV{VAR}...'
The above approaches change the environment for the shell, and all subsequent children it creates.