Question: Activity File: Lists and Loops In the previous activity we added variables to our script. We also added conditional flow control using if statements. Next,

Activity File: Lists and Loops
In the previous activity we added variables to our script. We also added conditional flow control using if statements.
Next, you will use loops to automate repetitive tasks in your script.
Loops facilitate code reuse, by allowing commands to be run many times without actually typing them repeatedly.
This adds another layer of sophistication and efficiency to your script.
To complete this activity, you will create several for loops that satisfy given requirements. If you get to the bonus, you can incorporate a for loop into your script.
Create your script file.
Create a new file named for_loops.sh and open it in your text editor.
Add the required boiler plate line at the top so your computer knows it's a bash script.
Create your variables
Create a variable that holds a list of 5 of your favorite U.S. states (e.g. Nebraska, Hawaii, California, etc.)
Create a for loop
Create a for loop that checks for the state 'Hawaii' in your list of states. If the 'Hawaii' is there, print "Hawaii is the best!". If is not there, print "I'm not fond of Hawaii".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!