Two commands in one line

110 views Asked by At

Why is it that:

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

gives me buffer and cache size, but

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

gives me only the cache size.

1

There are 1 answers

0
dieterxu On BEST ANSWER

From Bash man page:

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.

the && operator won't execute command2 until command1 exited with return value 0.

Is command free -s4 | cut -c67-,56-61 more close to what you want?