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 - 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
-
-
-
-
-
Conditional statements with the "if" keyword4m 17s
-
(Locked)
Working with "while" and "until" loops3m 57s
-
(Locked)
Introducing "for" loops4m 22s
-
(Locked)
Selecting behavior using "case"2m 11s
-
(Locked)
Using functions6m 17s
-
(Locked)
Reading and writing text files3m 25s
-
(Locked)
Challenge: Build a script using control structures33s
-
(Locked)
Solution: Build a script using control structures1m 18s
-
-
-
-