DEV Community

loading...

Discussion on: A Guide To Loving Your Terminal

Collapse
mitchartemis profile image
Mitch Stanley

Another bonus for the && syntax is that if the first command fails it will not run the second command.

This is useful if the second command relies on the first commands result (Like with your example updating packages).

If they're two separate commands that don't rely on each other then you can use ; instead.

Collapse
mithil467 profile image
Mithil Poojary

I use that with gcc.
gcc filename.c && ./a.out

If compilation failed, it won't run the program.

Collapse
samuelabreu profile image
Samuel Abreu

Also || is a valuable tool on scripts, to exit or inform an error:

do_something_amazing || echo “nope” && exit 1