The Execution Flow of Commands
Shell·3 min read·Jan 1, 2025
In programming, it often happens that a certain task requires the execution of multiple successive commands, which can be executed either sequentially or conditionally.
Sequential execution refers to the process of executing multiple commands, one after the other, in the order they are written.
Conditional execution, on the other hand, refers to the process of executing or skipping commands based on pre-determined conditions.
Executing commands sequentially
In Bash, there are essentially two ways to executes commands sequentially.
You can either type and execute one command at a time, awaiting for the prompt to reappear between each execution:
$ command1$ command2$ command3Or you can type all the commands in bulk on a single line, separated by a semicolon command separator ;, and automatically execute all of them in the order they are written:
$ command1 ; command2 ; command3Example
In this example, we are manually executing the echo command twice, one after the other:
$ echo HelloHello$ echo WorldWorldUnlock the CLI & Scripting with Bash module
Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.
You get immediate access to:
- 34 focused lessons across the CLI and Bash
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle