LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Only execute 2nd command on successufl execution of 1st command (https://www.linuxquestions.org/questions/linux-newbie-8/only-execute-2nd-command-on-successufl-execution-of-1st-command-748740/)

kregec05 08-19-2009 09:52 AM

Only execute 2nd command on successufl execution of 1st command
 
Hallo!

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?

PMP 08-19-2009 09:55 AM

Use &&

Command1 && command2

Command2 will execute only when command1 executes successfully

catkin 08-19-2009 10:14 AM

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
Code:

output="$(command 2>&1)"
The parsing is, of course, dependent on the particular command.

kregec05 08-19-2009 10:29 AM

works, thank you!


All times are GMT -5. The time now is 01:29 PM.