Skip to content

Demystifying &&, ||, and ! on Linux

The &&, ||, and ! operators allow you to run a lot of useful commands on Linux, but you first need to get used to syntax that is a little trickier than the if-then-else command you might normally use.

To get started, I should explain that one thing the command examples in this post have in common is the use of something that I might call a shorthand “if” test. Here’s an example:

$ [ -f donuts ]
$ echo %?

The -f donuts command asks if there is a file (-f) named “donuts”. Unless we display the return code afterwards with “echo $?”, the result of the test is not displayed. In this case, it’s false (i.e., not zero), so we know the file doesn’t exist. No donuts for us!

To read this article in full, please click here

Source:: Network World – Data Center