Cancel

Execute Multiple Commands at Once in Bash

You can execute multiple commands at once, which helps you to reduce your stress level.

Single line commands can be separated by semicolon after each command.

1
echo "run this first"; echo "run this second"; echo "run this third"

Run Z command only if X command is succeeded.

1
X && Z

Run Z command only if X command is failed.

1
X || Z

Run Z command only if X is succeeded, otherwise run Y command.

1
X && Z || Y

Run the following command as an example.

  • return "file is found!" only if cat command is succeeded.
  • Otherwise return "file cannot be found!".
1
cat hello.txt && echo "file is found!" || echo "file cannot be found!"