Last active
July 6, 2022 05:31
-
-
Save bernardolm/1c9e003a5f68e6e2534458fa758a096d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input=(73 foobar) | |
rg="^[+\-]{0,1}[0-9]+$" | |
for num in "${input[@]}"; do | |
(echo "${num//[^\-+0-9]/}" | grep -Eq $rg) \ | |
&& echo "$num is a number" \ | |
|| echo "$num is not a number"; | |
nnum="-"$num | |
(echo "${nnum//[^\-+0-9]/}" | grep -Eq $rg) \ | |
&& echo "$nnum is a number" \ | |
|| echo "$nnum is not a number"; | |
pnum="+"$num | |
(echo "${pnum//[^\-+0-9]/}" | grep -Eq $rg) \ | |
&& echo "$pnum is a number" \ | |
|| echo "$pnum is not a number"; | |
npnum="-+"$num | |
(echo "${npnum//[^\-+0-9]/}" | grep -Eq $rg) \ | |
&& echo "$npnum is a number" \ | |
|| echo "$npnum is not a number"; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will output: