What is Linux bash && Command Separator
In Shell scripting Often You will see multiple Linux bash commands run by spearing ‘&&’ sign. bash && use for executes sequence of commands one by one, but if one command failed reset of the commands will not execute. In other words, what bash && do is it runs multiple Linux commands one after another as long as there is no failure, if one command failed reset of the Linux commands will never execute.
cmd1 && cmd2 && cmd3
If cmd1 success, then execute the cmd2, if cmd2 success then execute cmd3. Likewise, if cmd1 fails cmd2 and 3 will not be executed.
Bash && example 1
cd /etc && wc -l hosts && cat hosts
Bash && example 2
cd /etc && wc -l nohosts && cat hosts
As per the above example, Second command failed because there is no file name nohosts inside the /etc directory. And as result third command never executes.
You can use bash && when you want to run multiple commands where you want all of them to be success to complete the task or otherwise it should stop executing.