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


  Search this Thread
Old 08-19-2009, 09:52 AM   #1
LQ Newbie
Registered: Aug 2009
Posts: 8

Rep: Reputation: 0
Question Only execute 2nd command on successufl execution of 1st command


I have a script which builds a project and then runs junit tests.
However, if the build fails, the junit tests fail with the same error message.
Therefore the command which runs the junit tests should only be executed if the build was successful.

Do you know a solution to this?
Old 08-19-2009, 09:55 AM   #2
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Use &&

Command1 && command2

Command2 will execute only when command1 executes successfully
Old 08-19-2009, 10:14 AM   #3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
PMP's suggestion works if the failed command sets a non-zero exit status (which almost all do). If it doesn't you need to capture the output and parse it for signs of success or failure
output="$(command 2>&1)"
The parsing is, of course, dependent on the particular command.
Old 08-19-2009, 10:29 AM   #4
LQ Newbie
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
works, thank you!


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
command execution time minil Programming 10 08-20-2010 04:59 PM
command execution gr8linux Linux - Newbie 14 05-28-2009 02:28 AM
Execute a command , reboot and then execute another command Linux - Newbie 3 12-03-2008 12:51 AM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM
command execution leonidas Linux - General 1 09-22-2004 12:29 AM > Forums > Linux Forums > Linux - Newbie

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

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