Little Girl's Mostly Linux Blog

CombineCommands

Combine commands

This page was last updated on July 25, 2011.

These are some methods for combining more than one command in Bash. Note that 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. Note: Those are backticks.


Obligatory Happy Ending

And they all lived happily ever after. The end.

Creative Commons License Except where otherwise noted, content on http://mostlylinux.wordpress.com is Copyright © 2007 – 2011 by Little Girl, licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License, and offered free of charge without warranty of any kind, either expressed or implied.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

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 )

Connecting to %s

Theme: WordPress Classic. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.