Article 5SG4E Using bash return status to validate numeric values

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"
}latest?d=yIl2AUoC8zA latest?i=wgfgVxqg_uY:BhYgUcaWVGY:F7zBnMy latest?i=wgfgVxqg_uY:BhYgUcaWVGY:V_sGLiP latest?d=qj6IDK7rITs latest?i=wgfgVxqg_uY:BhYgUcaWVGY:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments