Command1 && command2

The second command is only started if the first command is successful. To achieve this, the shell checks the exit (return) status of the first command and starts the second command only if and when that exit status is found to be 0:

    $ ls /home/ganesh  &&  echo "Command executed successfully"
    Since we are working as user ganesh,
    $ ls /root  && echo "Command executed successfully"

Since we are working as a normal user, we cannot access the /root directory. Therefore, nothing will be printed on screen.

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.