Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-23-2005, 02:54 PM
|
#1
|
|
LQ Newbie
Registered: Dec 2004
Posts: 22
Rep:
|
Very simple BASH scripting question
I have two commands, command1 and command2. In a script, I want to run command1, then once command1 is complete, I want to run command2. I can't remember what you put between commands to get the 2nd one to wait on the 1st to complete. I have tried the two that I thought it might be, "wait" and "&", with no luck
|
|
|
|
11-23-2005, 03:00 PM
|
#2
|
|
Member
Registered: Jul 2003
Location: portland
Distribution: debian testing
Posts: 68
Rep:
|
try &&
|
|
|
|
11-23-2005, 03:07 PM
|
#3
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
If you only want two to run if one was successful, do
what asb said; if you want it to run regardless of the
outcome of command1, use a semicolon.
command1; command2
as opposed to
command1 && command2
Cheers,
Tink
|
|
|
|
11-23-2005, 03:13 PM
|
#4
|
|
LQ Newbie
Registered: Dec 2004
Posts: 22
Original Poster
Rep:
|
Thanks. That worked. I knew it was something along those lines. I've been out of scripting for way too long.
|
|
|
|
11-23-2005, 03:31 PM
|
#5
|
|
Member
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 497
Rep:
|
Third way exists too, || can also be used in between the commands.
command1 || command2
in this case command2 gets executed if command1 fails.
|
|
|
|
11-23-2005, 04:12 PM
|
#6
|
|
LQ Newbie
Registered: Dec 2004
Posts: 22
Original Poster
Rep:
|
I actually needed &&, but I had never heard of || or ;. Those are good to know. I;m sure I'll run into situations where I need them. Thanks everyone.
|
|
|
|
11-23-2005, 04:28 PM
|
#7
|
|
Member
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 497
Rep:
|
It's really just basic boolen logic:
&& = and
Thus command1 && command2 means that is command1 gets executed without failing (i.e. is "true"), then command2 must get executed too.
|| = or
Thus either command1 OR command2 must be executed. Since command1 is tried first, command2 will get executed only if command1 fails (i.e. is "false").
It's the same thing as in bash if.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:49 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|