Hi,

p...@gmx.it wrote:
> I am not sure how 'env' command works.

Read the output of

  man env


> for example, what's the difference between '/usr/bin/perl' and 'env perl' ?

Reading the man page i'd say it's the same difference as between
"/usr/bin/perl" and "perl". I.e. the former runs explicitely a particular
program file, whereas the latter runs a program file which the shell
picks for you, depending on the setting of the PATH variable.

  echo "$PATH"


> I know env may set a environment variable in system,

Not "in system", but for the particular program run which gets started by
"env". "man env" says:

  SYNOPSIS
       env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

  DESCRIPTION
     Set each NAME to VALUE in the environment and run COMMAND.

The NAME=VALUE pairs will be in effect only as long as "env" and the
started program run.


(In a bash shell, the main advantages over plain
  [NAME=VALUE]... [COMMAND [ARG]...]
are probably the env option -i, which disables all inherited exported
variables, and -u which disables a particular inherited variable.)


> so my question also includes:
> 1. where to see a shell environment variable? I tried 'echo $ENV'
> showing nothing.

If you want to see all exported variables:

  env

because the statement in "man env":

  If no COMMAND, print the resulting environment.

Example shell session (with prompt "$"):

  $ export x=X
  $ y=Y
  $ echo "$x"
  X
  $ echo "$y"
  Y
  $ env | grep '^[xy]='
  x=X
  $

The not exported variale "y" does not show up in env's output.


> why 'env perl' just works?

Program "env" (or its helpers) finds a program file with name "perl"
in one of the directories which are listed in $PATH.


Have a nice day :)

Thomas

Reply via email to