From the course: Learning Bash Scripting

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Solution: Build a script using control structures

Solution: Build a script using control structures - Bash Tutorial

From the course: Learning Bash Scripting

Solution: Build a script using control structures

(upbeat music) - [Instructor] I chose to build a fortune telling game and I decided to include two random elements. When I run the script, I get a response while the program thinks, and then I get my reply. I'll run that again. Let's take a look at the script. Here at the top, I output a few lines using text formatting and some emojis. Then, I define two variables. waitingnumber is a random number from zero to three that'll determine which string we display to tell the user to wait. The next one, mysterynumber is a random number between one and 10 and this will correspond to the fortune that's returned. Next, I create an array called fortunes, which contains all of the possible responses to a question. Below that, I use a case statement using waitingnumber as an input. Regardless of the value, the script sleeps for one second, and then it outputs a pleasant message while the oracle is consulted. After that, it…

Contents