Cheat sheets

Run several commands on one line (&&, ; and ||)

Chain commands so the next one runs always, only on success or only on failure.

Handy? Press ⌘ DCtrl + D to bookmark this page for next time.

  1. Run the second only if the first worked
    Terminal
    npm install && npm run build
  2. Run both, whatever happens
    Terminal
    git pull ; npm test
  3. Run the second only if the first failed
    Terminal
    npm test || echo "Tests failed"
  1. Run the second only if the first worked
    Terminal · Ubuntu / Debian
    npm install && npm run build
  2. Run both, whatever happens
    Terminal · Ubuntu / Debian
    git pull ; npm test
  3. Run the second only if the first failed
    Terminal · Ubuntu / Debian
    npm test || echo "Tests failed"
  1. Run the second only if the first worked
    PowerShell
    npm install && npm run build

    && and || need PowerShell 7. In the older Windows PowerShell, use the ; line instead.

  2. Run both, whatever happens
    PowerShell
    git pull ; npm test
  3. Run the second only if the first failed
    PowerShell
    npm test || echo "Tests failed"