Articles

Shell script to check voting eligibility

Shell script to check voting eligibility


In this chapter of shell script, we will learn about:

  • shell script to check voting eligibility
  • shell script example if condition

Lets assume that a country allows its citizen to vote once they attain age of 18 years.

 

Suppose you wish to write a simple shell script example, that would:

  • accept user age as input and
  • then print message whether user is eligible to vote or not.

SHELL SCRIPT TO CHECK VOTING ELIGIBILITY

Given below is a shell script to find out the candidate eligible to vote based on age entered.

 

Here we have used if statement to validate the age. Notice that if statement ends with fi. That means everything in between if and fi is part of if statement body.

file: voting.sh

echo "Welcome to Voting booth"

echo "enter your age in integer"
read age

if [ $age -gt 17 ]
then
echo "Eligible to vote"
else
echo "Not Eligible to vote"
fi

OUTPUT

$ ./voting.sh
Welcome to Voting booth
enter your age in integer
18
Eligible to vote
 

Given below is the screenshot of the same shell script example if condition:

voting shell script

OUTPUT

voting shell script output

 

This is a simple shell script example programs that uses the shell script example if condition.


Shell Script Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Sonu Pandit
Technology geek, loves to write and share knowledge with the world. Having 10+ years of IT experience. B.Tech in Computer Science & Engineering
Page Views :    Published Date : May 28,2024  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!