From the course: Learning Bash Scripting

Unlock this course with a free trial

Join today to access over 24,900 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

For this challenge, I chose to build a fortune-telling game, and I decided to include two random elements. My solution is in the solutions directory, so let's move over there, and then I'll run my script. It's called fortune. When I run the script, I get a response while the program thinks, and then I get my reply. I'll run that again. Okay. Let's take a look at the script. Here at the top, I have a shebang and a comment to remind me what the script is for. Then I'm using echo -e to print out some formatted text. On the second line of output, I'm using some emojis and some control characters. Here, 3 will make the text italic, and 95 makes the text pink or magenta. Then I'm using echo to provide an empty line. After that, I'm defining two variables. They're called waitingnumber and mysterynumber. waitingnumber determines what we see when we first run the script, and mysterynumber determines our fortune. Below that, I declare an array called fortunes, and this contains my 10 possible…

Contents