Tag: char

  • Check if an input is numeric or char

     With this script you can check if an argument to a script is numeric, char or alphanumeric.

    [[ -z "$1" ]] && echo "I cant work without an input" && exit 1

    INPUT="$@"

    [[ "$INPUT" == ?(+|-)+([0-9]) ]] && echo "$INPUT is numeric" && exit 0

    [[ "$INPUT" == +([a-zA-Z]) ]] && echo "$INPUT is character" && exit 0

    [[ "$INPUT" == *([0-9]|[a-zA-Z])* ]] && echo "$INPUT is alpha-numeric" && exit 0