Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I always been using && but just saw someone uses ;.
What is the difference? When should I use ; or &&?

share|improve this question
There seems to be a big confusion here. ; and && are not equivalent. Please add the example where you saw this, it must make sense in the context of the problem – SuvP Apr 7 '14 at 7:12
duplicate of – Jasper Apr 7 '14 at 7:52
up vote 4 down vote accepted

The basic difference is that all commands separated by ; would be executed whereas when commands are separated by && then the subsequent command would be executed only if the previous exited with a return code of 0.

As such, when you say:

command1; command2; command3

the shell executes command1, then command2 and when the latter is also complete command3.

On the other hand,

command1 && command2 && command3

causes command1 to be executed. If it is successful, i.e. it exits with a return code of 0, then command2 is executed. Similarly, command3 is executed if the previous command executed successfully.

The latter construct is useful when you want to execute commands conditionally.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.