bashcutfree-command

Two commands in one line


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.


Solution

  • 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?