Tuesday, 11 June 2013

Shell Script to accept a character from user and display whether it is alphabet, digit, special character or user has entered more than one character.

Code:
echo -n "Enter the Character : "
read c
case $c in
        [ABCDEFGHIJKLMNOPQRSTUVWXYZZ]) echo "Alphabet";;
        [a-z]) echo "Alphabet";;
        [0-9]) echo "Digit";;
        ?) echo "special Character";;
        *) echo "More than two Characters";;
esac
let i=2
echo -n "1!"
while test $i -le $x
do
        echo -n " + $i !"
        let i=$i+1
done
echo " = $sum"

Output:
[ty2011330@localhost ~]$ sh j12.sh
Enter the Character : A
Alphabet
[ty2011330@localhost ~]$ sh j12.sh
Enter the Character : f
Alphabet
[ty2011330@localhost ~]$ sh j12.sh
Enter the Character : 90
More than two Characters

No comments:

Post a Comment