-3

env runs a command with a modified environment.

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

If there is no name=value or option following env, what kind of environment is a command executed with?

What is the purpose of using env without any name=value or option following?

For example

env bash -c 'echo "$_"'

Thanks.

Tim
  • 98,580
  • 191
  • 570
  • 977

1 Answers1

1

The output of

env cat /proc/self/environ

suggests that the environment is unchanged if nothing else is given.

(Or indeed, if I had bothered to read the fine manual, 'If no COMMAND, print the resulting environment', so plain env will be just fine.)

Ulrich Schwarz
  • 15,669
  • 4
  • 47
  • 58
  • Thanks. Then what is the difference between using `env` and not using `env`? What is the purpose of using `env` without any assignment following? – Tim Aug 02 '17 at 16:06
  • "no COMMAND" is indeed a totally different situation from no `name=value` and option – Tim Aug 02 '17 at 16:09
  • 1
    @Tim: you might find https://unix.stackexchange.com/a/29620/3929 helpful. In a nutshell, it can make sure you call a binary, not an alias or function, without knowing where exactly it is (other than in `$PATH`). – Ulrich Schwarz Aug 02 '17 at 16:11