In: Computer Science
Answer the same problem as the if statement assignment but use the case statement instead.
You are working for a company that offers driver licence training and you have been asked to write a script that asks your clients how old they are.
If he/she is 16 years old display the message "Please visit our company to take the test!"
If he/she is 15 years old display the message "Please take the training with us to learn how to drive!"
If he/she enters any other answer display the message. "Please visit out website to see our services!"
Name your script "case_statement.sh"
Be sure to include the standard header:
# Created by Your Name
# Assignment name
# Date
Do a screenshot of the code and the output. Submit as a single Word document
The name of the program here is written as main.sh. Please change the name of the program while submitting the assignment.
The syntax of case statements in a bash script is
case "$var" in
case1) #satement
case2) #statements
...
case*) #staements
esac
Code:
#!/bin/bash
echo "How old are you?"
read age #read the age from user input
#perform case statements to print the message based user input
# * indicates other than case 15 and case 16
case "$age" in
16) echo "Please visit our company to take the test!";;
15) echo "Please take the training with us to learn how to drive!";;
*) echo "Please visit out website to see our services!";;
esac
Output:
How old are you?
16
Please visit our company to take the test!
Please refer to the screenshots below for correct indentations