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:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: