&& Operator in Linux

&& operator (or AND operator) is used in bash scripting and in the terminal as well. When you use it in a terminal, it executes multiple commands in a single statement.

sudo apt update && sudo apt upgrade

Consider the single-line statement above. sudo apt update will execute (successfully) then the sudo apt upgrade command executes. If the sudo apt update fails or does not execute successfully, the sudo apt upgrade will also not execute.

sudo apt update sudo apt grade

In the attached screenshot below, you may notice that the sudo apt update did not execute successfully, then also the second statement didn’t execute.

sudo-apt-update-sudo apt-grade-2

You can also use this operator in scripting (when using multiple conditions).

Print Friendly, PDF & Email