Using bash return status to validate numeric values
by Faki from LinuxQuestions.org on (#5SG4E)
I have a bash function that returns a status, success if value is a positive integer, failure if value in not a positive integer
Code:isnumeric ()
{
posinteg=0
while (( $# > 0 )); do
case $1 in
--positive) posinteg=1 ;;
esac
done
k=0
[[ "$1" =~ ^\+?[0-9]+$ ]] && k=1
return "$k"
}I am having difficulty using isnumeric to check for positive integers. How can status be used to test something?
Code:ispositive ()
{
return isnumeric --positive "$1"
}
Code:isnumeric ()
{
posinteg=0
while (( $# > 0 )); do
case $1 in
--positive) posinteg=1 ;;
esac
done
k=0
[[ "$1" =~ ^\+?[0-9]+$ ]] && k=1
return "$k"
}I am having difficulty using isnumeric to check for positive integers. How can status be used to test something?
Code:ispositive ()
{
return isnumeric --positive "$1"
}