一行中的两个命令

Two commands in one line

为什么会这样:

free | cut -c67- && free | cut -c55-61  

给我缓冲区和缓存大小,但是

free -s4 | cut -c67- && free -s4 | cut -c55-61  

只给我缓存大小。

来自 Bash 手册页:

SHELL GRAMMA
   [...]
   Lists
        AND and OR lists are sequences of one of more pipelines separated by the && and || control operators,  respec‐
        tively.  AND and OR lists are executed with left associativity.  An AND list has the form

            command1 && command2

        command2 is executed if, and only if, command1 returns an exit status of zero.

在 command1 以 return 值 0 退出之前,&& 运算符不会执行 command2。

命令 free -s4 | cut -c67-,56-61 是否更接近您想要的?