LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 11-23-2005, 02:54 PM   #1
clickster
LQ Newbie
 
Registered: Dec 2004
Posts: 22

Rep: Reputation: 15
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
 
Old 11-23-2005, 03:00 PM   #2
asb
Member
 
Registered: Jul 2003
Location: portland
Distribution: debian testing
Posts: 68

Rep: Reputation: 15
try &&
 
Old 11-23-2005, 03:07 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 11-23-2005, 03:13 PM   #4
clickster
LQ Newbie
 
Registered: Dec 2004
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks. That worked. I knew it was something along those lines. I've been out of scripting for way too long.
 
Old 11-23-2005, 03:31 PM   #5
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
Third way exists too, || can also be used in between the commands.

command1 || command2

in this case command2 gets executed if command1 fails.
 
Old 11-23-2005, 04:12 PM   #6
clickster
LQ Newbie
 
Registered: Dec 2004
Posts: 22

Original Poster
Rep: Reputation: 15
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.
 
Old 11-23-2005, 04:28 PM   #7
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Shell Scripting Question hellomynameisphil Programming 2 08-27-2005 03:41 AM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 01:44 PM
simple scripting question wedgeworth Programming 6 02-04-2004 10:30 AM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 09:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration