Files
dabo/dabo/functions/g_num_is_higher.sh
2023-10-26 17:00:41 +02:00

38 lines
808 B
Bash

function g_num_is_higher {
local f_num=$1
local f_checkhigher=$2
# Check for integer (can be done with bash itself)
if [[ ${f_num} =~ ^[0-9]+$ ]] && [[ ${f_checkhigher} =~ ^[0-9]+$ ]]
then
# Check which is the low (from) and the high (to) number
if [ "${f_num}" -gt "${f_checkhigher}" ]
then
return 0
else
return 1
fi
fi
# Check for valid decimal number
for f_numtest in "$f_num" "$f_checkhigher"
do
if ! [[ ${f_numtest} =~ ^(-)?[0-9]+(\.[0-9]+)?$ ]]
then
g_echo "\"${f_numtest}\"Not a valid number"
return 1
fi
done
# Check which is the low (from) and the high (to) number
# Check if given number is in or out range
if [ $(echo "${f_num} > ${f_checkhigher}" | bc) -ne 0 ]
then
return 0
else
return 1
fi
}