Jump to content

Combining Commands


ac_dispatcher
 Share

Recommended Posts

I just bought my forth Linux book on Sunday (April 25 my birthday). I know their is a lot of stuff free on the web but I just wanted some good reference books. I now have

 

Linux Server Hacks <---great book

Linux Power Tools

Linux Pocket Guide

Essential System Admin Pocket Reference

 

Inspired by VeeDubb and I have decided to try a weekly/bi-weekly "AC's stupid tricks". A sort of newbie guide to some common things they may see. (maybe a little advanced to).

 

This week is Combining Commands (Linux Pocket Guide pg 26)

 

A lot of times you will come across some instructions that have lets say a "&&" in it. What does that mean/do? Here ya go -

 

Their are three basic ways you'll see commands combined:

 

$ command1 ; command2 ; command3

or

$ command1 && command2 && command3 <----- I have found this most common

or

$ command1 || command2 || command3

 

 

Explanation:

$ command1 ; command2 ; command3

The semi colon ";" is used to separate the commands. This command will invoke several commands in sequence.

 

$ command1 && command2 && command3

Now we have used a "&&" instead. This will also invoke a set of commands in sequence. The difference? It will stop execution if any command fails.

 

$ command1 || command2 || command3

Last is the "||" used to separate them. This will run a sequence of commands , stopping execution as soon as one succeeds.

 

 

Well I did not set out to tell you how you use these commands - thats for you to learn :P but hopefully you will know the use of ; or && or || in combining commands. Maybe some of the kind board folk can give some common examples?

 

 

Edit:

Not sure if this would be a "Tip" or "Trick". Not really sure where this post may belong. Mods / Admins feel free to move it. Thanks guys.

Edited by ac_dispatcher
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...