#!/bin/bash
# bash shell to illustrate numeric comparisons

if [ $# -lt 1 ]; then # Test whether an argument was givne
    echo "Usage: $0 number"
    exit
fi

v=$1

###############################################################
# example 1:  testing number:  v > 0
# Bourne shell style
if [ $v -gt 0 ]; then
   echo positive
fi 

# Korn shell style
if (( $v > 0 )); then
   echo positive
fi 


###############################################################
# example 2:  testing whether v <= 0
# Bourne shell style
if [ $v -le 0 ]; then
   echo non-positive
else 
   echo positive
fi 

# Korn shell style
if (( $v <= 0 )); then
   echo non-positive
else 
   echo positive
fi 


###############################################################
# example 3:  testing number: v < 0 and whether v = 0
# Bourne shell style
if [ $v -lt 0 ]; then
   echo negative
elif [ $v -eq 0 ]; then
   echo zero
else 
   echo positive
fi 

# Korn shell style
if (( $v <= 0 )); then
   echo non-positive
elif (( $v == 0 )); then
   echo zero
else 
   echo positive
fi 


###############################################################
# example 4: testing whether number v between 0 and 10, inclusive
if [ 0 -le $v  -a $v -le 10 ]; then
   echo between 0 and 10
else
   echo not between 0 and 10
fi

# Korn shell style
if (( (0 <= $v) && ($v <= 10) )); then
   echo between 0 and 10
else
   echo not between 0 and 10
fi

