Search⌘ K
AI Features

Combining Commands

Explore how to combine multiple Bash commands using semicolons and pipelines. Learn the differences in command execution order, dependencies, and how output streams affect command behavior for effective shell scripting.

Using semicolon

We already know how to combine Bash commands with pipelines and logical operators. However, there is a third way to do that. We can put a semicolon (;) as a delimiter between commands. In this case, Bash executes them one by one, from left to right, without any conditions. We get the linear sequence algorithm, in this case.

We’ll go through an example. Let’s suppose that we want to copy two directories to different target paths. A single cp call cannot do it. However, we can combine two calls into one command like this:

cp -R ~/docs ~/docs-backup ; cp -R ~/photo ~/photo-backup

Run the commands discussed ...