1

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 Answer 1

2

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.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.