Languages
[Edit]
EN

Bash - run one command after second one when first one is succeed and done

6 points
Created by:
Pearl-Hurley
559

In this short artlcle we would like to show how using Bash, run one command after second one only when first one succeed.

Quick solution:

first_command && second_command

 

Practical example

In this example, we present sleep and echo commands combining.

sleep 3 && echo "Sleep command done!"

Explaination:

  1. sleep command sleeps command line for 3 seconds returning success status when is done (0 status code),

  2. then echo command is run printing Sleep command done! text in the command line.

 

See also

  1. Bash - run one command after second one when first one fails

  2. Bash - run one command after second one regardless of the result

Alternative titles

  1. Bash - run a command after the previous finished with success status
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join