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?

2
  • 5
    It's a double-escaped &. It should say &&, not &&. Commented May 10, 2017 at 8:29
  • Today you'll learn: mojibake. :) Commented May 10, 2017 at 11:20

1 Answer 1

6

& 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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.