我需要命令 'env' 来设置临时环境变量吗?
Do I need the command 'env' for setting a temporary environment variable?
这两行命令有什么区别?
shy@nova:~/dev$ env TEST_VAR=demo mono test.exe
demo
shy@nova:~/dev$ TEST_VAR=demo mono test.exe
demo
shy@nova:~/dev$
test.exe 简单地写出 Environment.GetEnvironmentVariable("TEST_VAR") 的结果;到控制台。如您所见,无论有无 'env',它都适用于两种情况。
这有什么解释吗? 'env' 能否始终被省略,或者将其遗漏是一种不良行为?
env
is a shell command for Unix and Unix-like operating systems. It is used to either print a list of environment variables or run another utility in an altered environment without having to modify the currently existing environment.
[...]
To launch the X application xcalc and have it appear on a different display:
env DISPLAY=foo.bar:1.0 xcalc
Note that this use of env is often unnecessary since most shells support setting environment variables in front of a command:
DISPLAY=foo.bar:1.0 xcalc
所以,不,如果你的 shell 是“最 shell”之一。
试试这个来源
https://www.mkssoftware.com/docs/man1/env.1.asp.
据我所知,大多数 shell 不需要 env,除非您想显式设置或更改环境变量。
这两行命令有什么区别?
shy@nova:~/dev$ env TEST_VAR=demo mono test.exe
demo
shy@nova:~/dev$ TEST_VAR=demo mono test.exe
demo
shy@nova:~/dev$
test.exe 简单地写出 Environment.GetEnvironmentVariable("TEST_VAR") 的结果;到控制台。如您所见,无论有无 'env',它都适用于两种情况。
这有什么解释吗? 'env' 能否始终被省略,或者将其遗漏是一种不良行为?
env
is a shell command for Unix and Unix-like operating systems. It is used to either print a list of environment variables or run another utility in an altered environment without having to modify the currently existing environment.[...]
To launch the X application xcalc and have it appear on a different display:
env DISPLAY=foo.bar:1.0 xcalc
Note that this use of env is often unnecessary since most shells support setting environment variables in front of a command:
DISPLAY=foo.bar:1.0 xcalc
所以,不,如果你的 shell 是“最 shell”之一。
试试这个来源 https://www.mkssoftware.com/docs/man1/env.1.asp.
据我所知,大多数 shell 不需要 env,除非您想显式设置或更改环境变量。