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.

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.

  • 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 1 '16 at 16:01
  • I edited the answer to be more verbose – schily Jul 4 '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 5 '16 at 11:04
  • envprints everything it received from the shell. – schily Jul 5 '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 5 '16 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.