Posted By

yoblob on 02/24/11


Tagged

Bash


Versions (?)

check type of input


 / Published in: Bash
 

checks for number character alphanumeric

  1. [[ -z "$1" ]] && echo "I cant work without an input" && exit 1
  2.  
  3. INPUT="$@"
  4.  
  5. [[ "$INPUT" == ?(+|-)+([0-9]) ]] && echo "$INPUT is numeric" && exit 0
  6.  
  7. [[ "$INPUT" == +([a-zA-Z]) ]] && echo "$INPUT is character" && exit 0
  8.  
  9. [[ "$INPUT" == *([0-9]|[a-zA-Z])* ]] && echo "$INPUT is alpha-numeric" && exit 0

Report this snippet  

You need to login to post a comment.