Answered by : charlesalexandre-roy
# Basic syntax:
# This will run command_2 after command_1 regardless of whether command_1
# completes successfully or not:
command_1; command_2
# This will run command_2 after command_1 if command_1 completes successfully:
command_1 && command_2
# This will run command_2 after command_1 if command_1 fails:
command_1 || command_2
# This will pass (pipe) the standard output of command_1 to command_2:
command_1 | command_2
Source : https://dev.to/0xbf/run-multiple-commands-in-one-line-with-and-linux-tips-5hgm | Last Update : Mon, 08 Aug 22
Answered by : toma-alimos
A; B # Run A and then B, regardless of success of A
A && B # Run B if and only if A succeeded
A || B # Run B if and only if A failed
A & # Run A in background.
Source : https://askubuntu.com/questions/334994/which-one-is-better-using-or-to-execute-multiple-commands-in-one-line | Last Update : Tue, 19 Oct 21
Answered by : charlesalexandre-roy
# Basic syntax:
for i in a b; do echo $i; printf "$i\t$i\n"; done
# Where:
# - each command in the for loop needs to be separated by semicolons. Here
# we echo $i and then print $i<tab>$i<newline>
# - over several lines this would be equivalent to:
for i in a b
do echo $i printf "$i\t$i\n"
done
Source : https://ma.ttias.be/bash-loop-first-step-automation-linux/#:~:text=Chaining%20multiple%20commands%20in%20the,ones%20inside%20the%20for%2Dloop.&text=You%20can%20chain%20multiple%20commands,'re%2C%20well%2C%20done. | Last Update : Tue, 22 Feb 22
Answered by : matthew-edelen
command1 && command2 OR
command1; command2 OR
command1 || command2
Source : | Last Update : Wed, 04 May 22
Answered by : niransha
# cmd1 && cmd2
$ cd myfolder && ls # run ls only after cd to myfolder
# cmd1; cmd2
$ cd myfolder; ls # no matter cd to myfolder successfully, run ls
# cmd1 || cmd2
$ cd myfolder || ls # if failed cd to myfolder, `ls` will run
Source : https://dev.to/0xbf/run-multiple-commands-in-one-line-with-and-linux-tips-5hgm | Last Update : Fri, 25 Dec 20