Introduction
Bash is a popular Unix shell and command language. It is used to automate repetitive tasks, manage system configurations, and execute complex scripts. In this challenge, we will explore how to use the else if statement in Bash.
Bash is a popular Unix shell and command language. It is used to automate repetitive tasks, manage system configurations, and execute complex scripts. In this challenge, we will explore how to use the else if statement in Bash.
The problem is to create a Bash script that uses the else if statement to check a user's lucky number and award prizes accordingly. The script should prompt the user to enter their lucky number and then check it against a set of predefined values. If the number matches one of the values, the script should print a message indicating the prize the user has won. If the number does not match any of the values, the script should print a message indicating that the user did not win a prize.
~/project/elseif_example.sh
.To run the script, use the following command:
bash elseif_example.sh
Output:
Enter your lucky number
101
You got 1st prize
In this challenge, we learned how to use the else if statement in Bash to check a user's lucky number and award prizes accordingly. We also learned how to prompt the user for input and how to use conditional statements to control the flow of the script. With these skills, we can create more complex Bash scripts to automate tasks and manage system configurations.