Numbers in BASH | skybert.net

Numbers in BASH


Testing if a variable is numeric

local days=$1
if [[ $days =~ ^[0-9]*$ ]]; then
   echo "You entered number of days: ${days}"
fi

Testing if a variable is not numeric

local days=$1
if [[ ! $days =~ ^[0-9]*$ ]]; then
  echo "Usage: $(basename $0) <number-of-days>"
  exit 1
fi

gmail torstein.k.johansen @ gmail ~ twitter @torsteinkrause ~