Why should I use env before the command?

I saw prefix commands (interactive) of colleagues' commands with env, for example, env KEY=value my_scriptto call my_script.

My question is: what's the point of using envhere? Why don't you just write KEY=value my_script?

I understand what I am doing env, and the use of such cases as #!/usr/bin/env pythonmakes sense. But I do not understand why you are a prefix envfor commands in an interactive shell.

+4
source share
1 answer

There are probably no good reasons why you will need to use envthe interactive team.

In the Bourne-derived shell (sh, ksh, bash, zsh), these two commands:

key=VALUE my_script
env key=VALUE my_script

essentially identical.

, key=Value , . env - ( ). - , env, , , . , find -exec:

find . -type f -exec some_command \;

some_command find, , key=Value . env, .

, .

, csh tcsh ( Bourne) . -, csh tcsh , env key=Value my_script .

- , env , , .

. , , , , .

chepner, env , ( ), -i .

( #!/usr/bin/env hack, . . )

+8

All Articles