Dup Ver Goto 📝

Regexes1

PT2/lang/bash/variables does not exist
To
14 lines, 80 words, 627 chars Page 'Regexes1' does not exist.

Test for Numeric

Sources: stackoverflow 806906 answer by F. Hauri "Some performance and compatibility hints"

isuint_Regx() { [[ $1 =~ ^[0-9]+$ ]] ;}
isint_Regx() { [[ $1 =~ ^[+-]?[0-9]+$ ]] ;}
isnum_Regx() { [[ $1 =~ ^[+-]?([0-9]+([.][0-9]*)?|\.[0-9]+)$ ]] ;}

Note that a more efficient way is using case, viz:

isuint_Case() { case $1 in ''|*[!0-9]*) return 1;;esac;}
isint_Case() { case ${1#[-+]} in ''|*[!0-9]*) return 1;;esac;}
isnum_Case() { case ${1#[-+]} in ''|.|*[!0-9.]*|*.*.*) return 1;; esac ;}