In this tutorial we are writing a Shell Program to Check Eligibility for voting.
To check that a person is eligible for voting or not, we need to check whether person’s age is greater than or equal to 18. For this we are reading age in a variable a and checking the condition a>=18, if the condition is true, “person will be eligible for voting” else not.
Program Source Code : Shell program to check eligibility for voting
1 2 3 4 5 6 7 8 9 10 |
echo Enter the Age: read age if (( $age >=18 )) then echo "ELIGIBLE FOR VOTING" else echo "INVALID" fi |
Output:
1 2 3 4 5 6 7 8 9 10 |
teen@teen-VirtualBox:~$ bash vote.sh Enter the Age: 13 INVALID teen@teen-VirtualBox:~$ bash vote.sh Enter the Age: 37 ELIGIBLE FOR VOTING |