Unix script to analyze the input, depending on the type of character -
i having time script here
- the script reads character keyboard.
- depending on type of character, script displays 1 of following messages
uppercase letter lowercase letter digit special character.
#!/bin/bash echo 'enter single character:' read $1 if $1 = "a-z" echo 'uppercase letter' fi if $1 = "a-z" echo 'lowercase letter' fi if $1 = [ ! @ $ ^ & * ~ ? . | / [ ] < > \ ` " ;# ( )] echo 'special character' fi though not working properly.
here short working one:
#!/bin/bash echo "enter single character:" read input_source case "$input_source" in [[:lower:]]) echo "lowercase letter" ;; [[:upper:]]) echo "uppercase letter" ;; [0-9] ) echo "digit";; * ) echo "special character";; esac
usage () { echo usage: $0 char exit } [[ $1 ]] || usage if [[ $1 =~ [[:upper:]] ]] echo 'uppercase letter' elif [[ $1 =~ [[:lower:]] ]] echo 'lowercase letter' elif [[ $1 =~ [[:punct:]] ]] echo 'special character' fi
Comments
Post a Comment