Hi
What is the difference between following commands
Command1
length=1
if [[ $length > 15 ]] ; then
echo "Hellow world"
fi
Command 2
length=1
if [[ $length -gt 15 ]] ; then
echo "Hellow world"
fi
which is correct usage from this
Hi
What is the difference between following commands
Command1
length=1
if [[ $length > 15 ]] ; then
echo "Hellow world"
fi
Command 2
length=1
if [[ $length -gt 15 ]] ; then
echo "Hellow world"
fi
which is correct usage from this
Both would work on a recent version of bash, probably a version more than 3.
Otherwise use the old syntax:
if [ $x -gt 5 ]
then
echo "hello"
fi
The [[ ]] syntax is a Conditional Expression and is described in the "Conditonal Expressions" section of your Shell Manual.
The [ ] syntax is a Test and is described in the "test" Shell command which is usually a superset of the unix "test" command.
Though there is much overlap in the syntax, the two forms are not interchangeable.
Beware of this classic mistake:
a=1
b=2
if [ $a > $b ]
then
echo ok
else
echo not ok
fi
Replies "ok" and CREATES A FILE CALLED "2" !