Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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