Little Girl's Mostly Linux Blog

CombineCommands

Combine commands

This page was last updated on September 29, 2013.

These are some methods for combining more than one command in Bash. Although the examples show only two commands strung together, you can continue adding semi-colons, pipes, ampersands, etc., to add more commands.

Syntax Description
command1 | command2
Execute command1. Use its output as input for command2.
command1 || command2
Execute command1. If it fails, execute command2.
command1 && command2
Execute command1. If it works, execute command2.
command1; command2
Execute command1 and command2 regardless of whether either of them fail.
command1 $(command2)
Execute command2. Use its output as input for command1.
command1 `command2 -options`
Execute command2. Use its output as input for command1.

Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Create a free website or blog at WordPress.com.