EN
Bash - run one command after second one regardless of the result
0
points
In this short artlcle we would like to show how to run one command after second one regardless of the result using Bash.
Quick solution:
first_command; second_command
Practical examples
Example 1 - both commands success
In this example, we combine sleep and echo commands.
Bash command:
sleep 3; echo "Sleep command done!"
Output:
Sleep command done!
Explaination:
-
sleepcommand executes successfully suspends the calling shell script for3secons, -
then echo
commandis executed printing text in the command line.
Example 2 - fail & success
In this example, we use ls and echo commands .
Bash command:
ls /path/to/unexisting/directory; echo "echo command done!"
Output:
ls: cannot access '/path/to/unexisting/directory': No such file or directory
ls command has failed and done!
Explaination:
-
lscommand tries to list files under not existing directory and fails, -
then echo
commandis run printing text in the command line.