Introduction
Bash is a popular shell used in Linux and Unix operating systems. It provides a powerful command-line interface for users to interact with the system. In this challenge, we will explore the use of the case statement in Bash scripting.
Bash is a popular shell used in Linux and Unix operating systems. It provides a powerful command-line interface for users to interact with the system. In this challenge, we will explore the use of the case statement in Bash scripting.
You need to write a Bash script that takes user input for their lucky number and outputs a message based on the number entered. If the number entered matches a specific value, the script will output a prize message. If the number entered does not match any of the specific values, the script will output a message to try again next time.
~/project/case_example.sh
.#!/bin/bash
shebang at the beginning of the script.To run the script, use the following command:
bash case_example.sh
Output:
Enter your lucky number
101
You got 1st prize
In this challenge, we learned how to use the case statement in Bash scripting. The case statement provides an alternative to the if-elseif-else statement and can be used to check multiple values of a variable. By using the case statement, we were able to create a script that outputs a message based on the user's input.