Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Shell管道$()vs direct命令_Bash_Redirect_Pipe - Fatal编程技术网

Bash Shell管道$()vs direct命令

Bash Shell管道$()vs direct命令,bash,redirect,pipe,Bash,Redirect,Pipe,新手到shell编程 要运行命令并将其输出放入变量中,我们使用: var=$(command) 命令和$(命令)之间的重定向管道有什么区别。 作品: 错误 在子shell中执行,然后将输出放在原始命令中。 所以,基本上你是在做这件事 $(command) | while read line # Example result-of-command | while read line # Bash reads 阅读有关命令替代的更多信息,或者将$()想象成一个shell

新手到shell编程

要运行命令并将其输出放入变量中,我们使用:

var=$(command)
命令和$(命令)之间的重定向管道有什么区别。

作品:

错误

子shell中执行,然后将输出放在原始命令中。 所以,基本上你是在做这件事

$(command)        | while read line    # Example
result-of-command | while read line    # Bash reads
阅读有关命令替代的更多信息,或者

将$()想象成一个shell,您可以在其中键入内容
$(command) | while read line
do
  echo $line
done
$(command)        | while read line    # Example
result-of-command | while read line    # Bash reads