1

I learned about the command line command test and read a few examples. One of them was obscure to me:

 test 100 -gt 99 && echo "Yes, that's true." || echo "No, that's false."

I understand it to this point:

test 100 -gt 99 

evaluates whether 100 is greater than 99

echo "Yes, that's true." || echo "No, that's false."

If the expression turns out to be true do the command on the left of the double pipe symbol, otherwise do the right one.

I could not find any hint onto the &amp expression in the manual.

What is its purpose?

4

& doesn't mean anything to test, it's the HTML entity for the ampersand &, which has a special meaning in HTML so it cannot be presented as-is. Where ever that snippet came from, the presentation is broken.

Decoding that character, the line should be

test 100 -gt 99 && echo "Yes..." || echo "No..."

&& and || still don't have anything to do with test itself, but are conditional constructs for the shell. cmd1 && cmd2 runs first cmd1 then, if it returns a truthy value (zero), runs cmd2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.