10.3.10 isNumericStr (evaluates numeric characters)
Syntax
isNumericStr character-string
Description
This command evaluates whether the character string specified for the argument can be evaluated as numeric characters.
Numeric characters have the following syntax (example: 123, -100, 001).
[-]<Numeric characters>+
This command outputs 1 in the following cases:
-
The character string can be evaluated as numeric characters
This command outputs 0.
-
The character string cannot be evaluated as numeric characters
Arguments
- character-string
-
This command specifies the character string to be evaluated.
Output to the standard output
1 or 0.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
Not less than 1 |
Termination with an error |
Examples
isNumericStr 123 # "1" is output. isNumericStr -100 # "1" is output. isNumericStr 001 # "1" is output. isNumericStr +5 # "0" is output. isNumericStr abc # "0" is output. # If the value of the variable var1 cannot be evaluated, return 1. result=$(isNumericStr "$var1") if [[ $result -eq 0 ]]; then return 1 fi