bash - 内联评估 bash/zsh 表达式

标签 bash zsh

我知道可以做类似的事情

echo `ls` "foobar"
echo $(ls) "foobar"

但是当我尝试做类似的事情时

diff `pip freeze` requirements.txt
diff $(pip freeze) requirements.txt

它失败了。

我在这里错过了什么?谢谢!

P.S 我正在使用 zsh shell。

最佳答案

diff命令确实期望文件名作为它的参数,而不是字符串。像这样的东西:

diff file1 file2

不是:

diff "$string1" "$string2"

如果你想区分两个命令的输出(或者在你的情况下是针对静态文件的命令输出),你可以使用 process substitution:

diff <(pip freeze) requirements.txt

<()将重定向 pip freeze 的输出到 /dev/fd[0-9] 的文件中.此文件名随后将传递给 diff .

关于bash - 内联评估 bash/zsh 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29696811/

相关文章:

bash - Bash 中双引号前的美元字符

ubuntu - 错误 : "...Z Shell configuration function for new users, zsh-newuser-install(...)"

git - `git branch` 输出为空,在 macOS 上没有 `sudo`

bash - 为 zsh + Prezto 主题安装电力线字体

bash - 历史扩展在 .zshrc 函数中不起作用

bash - 试图删除我的 .git 文件夹和 'rm -r .git --force' 不起作用

bash - 在 bash 中将十六进制字节发送到串行

bash - 在 AWK 中比较工程编号时出现奇怪的输出

bash - bash 中的数字和字符串操作

while-loop - 如何在 zsh 中一次一个单词地遍历字符串