Interview Prep/Shell Scripting/Shells, scripts and execution

What is the difference between `;`, `&&`, `||` and `&` between commands?

BeginnerConceptShells, scripts and execution
Answer
  • a ; b runs b after a, regardless of result.
  • a && b runs b only if a succeeded (exit 0).
  • a || b runs b only if a failed.
  • a & b runs a in the background and b immediately.
mkdir -p /srv/app && cd /srv/app || exit 1
systemctl is-active --quiet nginx || systemctl restart nginx

a && b || c is not if/else: c also runs when b fails.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Shells, scripts and execution