Tuesday, 11 June 2013

Shell Script to accept a number from user and print the day of the week using case … in

Code:
echo -n "Enter the day number : "
read num
case $num in
        1) echo "Sunday";;
        2) echo "Monday";;
        3) echo "Tuesday";;
        4) echo "Wednesday";;
        5) echo "Thursday";;
        6) echo "Friday";;
        7) echo "Saturday";;
        *) echo "Enter any number between 1 to 7."
esac


Output:
[ty2011330@localhost ~]$ sh j06.sh
Enter the day number : 1
Sunday
[ty2011330@localhost ~]$ sh j06.sh
Enter the day number : 3
Tuesday
[ty2011330@localhost ~]$ sh j06.sh
Enter the day number : 2
Monday
[ty2011330@localhost ~]$ sh j06.sh
Enter the day number : 4
Wednesday
[ty2011330@localhost ~]$ sh j06.sh
Enter the day number : 5
Thursday
[ty2011330@localhost ~]$ sh j06.sh
Enter the day number : 6
Friday

No comments:

Post a Comment