Languages
[Edit]
EN

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

0 points
Created by:
Nataniel-Barclay
499

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

Quick solution:

 

Practical example

Edit

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

Bash command:

Output:

 

Explaination:

  1. ls command tries to list files under not existing directory and fails,

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

 

See also

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

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

Alternative titles

  1. Bash - run one command after second one when first one has failed
1
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