Bash 如何在利用短路的同时进行涉及管道命令返回值的逻辑测试?

Bash 如何在利用短路的同时进行涉及管道命令返回值的逻辑测试?,bash,Bash,这是我试图纠正的代码,但我知道它在逻辑上是不正确的,仅绑定到第一个测试 # if Vim was compiled in the same month, skip. if ! [[ -f /usr/local/bin/vim ]] && /usr/local/bin/vim --version | grep "compiled $(date +%b) [0-9]{1,2} $(date +%Y) " - 我知道这在逻辑上是错误的原因是: $ if ! [[ a == b ]]

这是我试图纠正的代码,但我知道它在逻辑上是不正确的,
仅绑定到第一个测试

# if Vim was compiled in the same month, skip.
if ! [[ -f /usr/local/bin/vim ]] && /usr/local/bin/vim --version | grep "compiled $(date +%b) [0-9]{1,2} $(date +%Y) " -
我知道这在逻辑上是错误的原因是:

$ if ! [[ a == b ]] && [[ c == c ]]; then echo yy; fi
yy

$ if ! [[ a == a ]] && [[ a == c ]]; then echo yy; fi

$

我认为解决办法是使用卷发:

$ if ! { [[ a == a ]] && [[ a == c ]]; }; then echo yy; fi
yy
我不知道有没有更高雅的

if [[ a != a ]] || [[ a != c ]]; then echo yy; fi
或:


另外:
[(a!=a)| |(a!=c)];然后回音yy;fi
Ah,但是你看,我需要卷曲,因为管道命令的通过/失败条件不能填充到
[[
测试中!无论如何,你的第二个示例非常好,因为如果缺少可执行文件,它会隐式失败。
if ! /usr/local/bin/vim --version 2> /dev/null | grep "compiled ...