Difference between revisions of "Execute Multiple BASH Shell Commands"
From Free Knowledge Base- The DUCK Project: information for everyone
(Created page with "How to run shell commands sequentially or at the same time entered on a single line. echo 1 sleep 5s echo 2 echo 1; sleep 5s; echo 2 echo 1 && sleep 5s && echo 2") |
|||
Line 4: | Line 4: | ||
sleep 5s | sleep 5s | ||
echo 2 | echo 2 | ||
+ | |||
+ | (A) run several commands using the control operator ";" (semicolon) which will execute them sequentially. The shell will wait for each command to terminate in turn. The return status is the exit status of the last command executed. | ||
echo 1; sleep 5s; echo 2 | echo 1; sleep 5s; echo 2 | ||
+ | |||
+ | (B) run several commands using the control operator "&" (ampersand) | ||
+ | |||
+ | echo 1 & sleep 5s & echo 2 | ||
+ | |||
+ | (C) run several commands using double ampersands | ||
echo 1 && sleep 5s && echo 2 | echo 1 && sleep 5s && echo 2 |
Revision as of 14:54, 1 April 2014
How to run shell commands sequentially or at the same time entered on a single line.
echo 1 sleep 5s echo 2
(A) run several commands using the control operator ";" (semicolon) which will execute them sequentially. The shell will wait for each command to terminate in turn. The return status is the exit status of the last command executed.
echo 1; sleep 5s; echo 2
(B) run several commands using the control operator "&" (ampersand)
echo 1 & sleep 5s & echo 2
(C) run several commands using double ampersands
echo 1 && sleep 5s && echo 2