Bash: Run command after another

What many of you probably know is that you can chain commands together with the semicolon. Like so:

unixbench ; echo "unixbench finished" >> unixbench.log

So here we’re running a unixbench, and then directly after, we’re appending “unixbench finished” to unixbench.log.

But what you might not know about is the ‘&&’ replacement for ‘;’. This will only do the next command if the first command returns 0, meaning clean finish.

unixbench && echo "unixbench finished cleanly" >> unixbench.log

And taking it a step further, there’s ‘||’ which does the opposite of ‘&&’. If the first command fails, then the next command happens.

unixbench || echo "unixbench failed" >> unixbench.log


Leave a Reply

Your email address will not be published. Required fields are marked *