Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that in Bash if statements can be evaluated with expr by using:

if [[ 5 > 0 ]]; then echo true; fi

How does Bash evaulate the following form of if?

if [ 5 -gt 0 ]; then echo true; fi
share|improve this question
up vote 2 down vote accepted

The first one perform a string lexicographic comparison and is bash only, while the second perform a numeric comparison and works also in POSIX shell.

The second one could be better written in bash as

if ((5 > 0)); then echo "true"; fi
share|improve this answer
Wonderful. Thank you. – user13091 Dec 27 '11 at 22:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.