-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.

4
  • Can you not see this with env bash -c 'set'?
    – DopeGhoti
    Commented Aug 2, 2017 at 16:02
  • Do you mean see bash: set: No such file or directory after running env bash -f 'set'?
    – Tim
    Commented Aug 2, 2017 at 16:03
  • Typo corrected.
    – DopeGhoti
    Commented Aug 2, 2017 at 16:05
  • 1
    set display all the shell variables and functions. What is it to do with environment variables?
    – Tim
    Commented Aug 2, 2017 at 16:26

1 Answer 1

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.)

3
  • 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
    Commented Aug 2, 2017 at 16:06
  • "no COMMAND" is indeed a totally different situation from no name=value and option
    – Tim
    Commented Aug 2, 2017 at 16:09
  • 1
    @Tim: you might find 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). Commented Aug 2, 2017 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .