Bash/sh - difference between && and ;

psihodelia picture psihodelia · May 27, 2011 · Viewed 54.4k times · Source

I normally use ; to combine more than one command in a line, but some people prefer &&. Is there any difference? For example, cd ~; cd - and cd ~ && cd - seems to make the same thing. What version is more portable, e.g. will be supported by a bash-subset like Android's shell or so?

Answer

ignar picture ignar · May 27, 2011

If previous command failed with ; the second one will run.

But with && the second one will not run.

This is a "lazy" logical "AND" operand between operations.