相关疑难解决方法(0)

这个 shell/Bash 语法是什么:someVariable=someValue someCommand

我的一位同事为我提供了一种我不熟悉的 Bash 语法。我的 Google foo 无法弄清楚它的作用以及为什么/何时应该使用它。

他发给我的命令是这样的:

someVariable=something command
Run Code Online (Sandbox Code Playgroud)

最初,我认为这等效于以下内容:

someVariable=something ; command
Run Code Online (Sandbox Code Playgroud)

或者

someVariable=something 
command
Run Code Online (Sandbox Code Playgroud)

但事实并非如此。例子:

[Jan-03 11:26][~]$ # Look at the environment variable BAZ. It is currently empty
[Jan-03 11:26][~]$ echo $BAZ

[Jan-03 11:27][~]$ # Try running a command of the same format    
[Jan-03 11:27][~]$ BAZ=jake echo $BAZ

[Jan-03 11:27][~]$    
[Jan-03 11:27][~]$ # Now, echo BAZ again. It is still empty:    
[Jan-03 11:27][~]$ echo $BAZ

[Jan-03 11:27][~]$    
[Jan-03 11:28][~]$    
[Jan-03 11:28][~]$ # If we add a semi-colon to …
Run Code Online (Sandbox Code Playgroud)

command-line shell bash environment-variables

27
推荐指数
3
解决办法
2553
查看次数

标签 统计

bash ×1

command-line ×1

environment-variables ×1

shell ×1