Sobes.tech
Junior — Middle

How to execute multiple Bash commands simultaneously in a single line in the terminal?

sobes.tech AI

Answer from AI

In Bash, you can execute multiple commands on one line using special separators:

  • ; — execute commands sequentially, regardless of the previous command's result.
  • && — execute the next command only if the previous one succeeded (exit code 0).
  • || — execute the next command only if the previous one failed (exit code not 0).

Examples:

# Execute command1, then command2 regardless of the result
command1; command2

# Execute command2 only if command1 was successful
command1 && command2

# Execute command2 only if command1 failed
command1 || command2