Search code examples
shellksh

How to determine if a string is numeric in ksh


I'm trying to validate input in ksh, and would like to know the easiest way to determine if a string is a valid number.


Solution

  • Have a go with :

        case $INPUT in
            +([0-9])*(.)*([0-9]) )
                  # Variable is numeric
                  ;;
            *) 
                  # Nope, not numeric
                  ;;
    
    esac