0

coreutils manual says about env command that

env [option]... [name=value]... [command [args]...]

If no command name is specified following the environment specifications, the resulting environment is printed. This is like specifying the printenv program.

is the printed environment by env specific to env, in the sense that the value of _ depends on env? For example,

$ env | grep '^_'
_=/usr/bin/env

Does env print out almost all the the exported environment of the current shell, except that the value of the environment variable _ is modified to be specific to env?

So is env not to print out the environment in the current shell, but the environment received within env?

Thanks.

Tim
  • 101,790

1 Answers1

1

env is a separate program in most shells, so it prints the environment it received from the shell.

The Bourne Shell uses an environment management system based on shell variables.

At startup, it imports the environment into the list of shell variables.

Creating or modifying shell variables does not modify the environment that the shell sets up for new programs.

  • calling set prints the internal shell variables as set is built into the shell

  • calling env prints the exported environment as env is an external command

The shell variable _ was introduced by ksh88. It holds the last command.

schily
  • 19,173
  • thanks. is 'the environment it received from the shell' different from the environment which a command different from env received from the shell, because the value of _ is command-specific? – Tim Jul 01 '16 at 16:01
  • I edited the answer to be more verbose – schily Jul 04 '16 at 10:58
  • Thanks. Does env print out almost all the the exported environment of the current shell, except that the value of the environment variable - is modified to be specific to env? See the exampled I added to my post. – Tim Jul 05 '16 at 11:04
  • envprints everything it received from the shell. – schily Jul 05 '16 at 13:02
  • sorry, in my last comment, I meant the value of the environment variable _, instead of -, is modified to be specific to env. So doesn't the value of _ in the output of env depend on env, and not on the current shell? – Tim Jul 05 '16 at 13:04
  • No, the shell just creates a new environment from the shell variables (by looking at the epxort attributes) for every new external command. – schily Jul 05 '16 at 13:07
  • So is the output of env the environment that the shell passes to env? Does the environment that env receives contain environment variables whose values are specific to env, such as _ whose value is set to /usr/bin/env? – Tim Jul 05 '16 at 16:45
  • As mentioned in the answer: env is not part of the shell. – schily Jul 05 '16 at 17:09