What if the first command fails?

062

If the first command fails when using &&, the second command will not be executed. The execution stops at the first command, and any subsequent commands chained with && will be skipped.

For example:

mkdir existing_directory && echo "Directory created"

If existing_directory already exists, the mkdir command will fail, and the message "Directory created" will not be printed. Only if mkdir succeeds (i.e., the directory is created), will the echo command run.

0 Comments

no data
Be the first to share your comment!