{ads}

Demystifying &&, ||, and ! on Linux



April 12, 2022 at 04:24AM

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 %?
1

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



from Network World https://ift.tt/omFdV2q

0 Response to "Demystifying &&, ||, and ! on Linux"

Post a Comment

Article Top Ads

Central Ads Article 1

Middle Ads Article 2

Article Bottom Ads