Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy/Paste your script from 4b here . Let's look at a more complicated script. a. Write the following as script6.sh and change its permissions to

Copy/Paste your script from 4b here

.image text in transcribed

Let's look at a more complicated script. a. Write the following as script6.sh and change its permissions to executable. #!/bin/bash count=0 for num in $@; do if [$num -eq 10]; then count=$((count+1)) fi done echo The number 10 was found $count times Run the script as./script6.sh 10 20 30 10 40 20 50 10 60 . What is the output? Summarize what the script does. b. Values can be input by the user using the read command. The following script inputs information from the user and outputs it. #!/bin/bash echo -n "Enter your name: " read name echo Hello $name Note that the -n in the echo statement forces echo to not output a new line character so that "Enter your name:" and the input appear on the same line. To provide some spaces after "name: ", we use the quote marks in the echo statement. Modify script6.sh from 4a to output a message to the user asking them to specify a target value to compare with using an echo statement, and then input a value from the user using a read statement. Both of these statements must appear before the for loop. Store the user's input value in a variable called target. Now, instead of comparing num to 10, compare num to target. Run the script as you did in 4a, but when asked, enter the value 20. If you did not get the right answer (2), check your script to see if you can figure out what is wrong. Try your script out with different target values (10, 40, 80). When it runs correctly for all of these, copy the script into your answer file. Exit vi. The for loop can be used to iterate through more than just the current directory or the list of parameters. It can iterate over the result of any Linux command. Recall the cat command outputs the contents of a file. Using this in a for loop allows you to iterate over each string found in the file. Strings are delineated with white spaces (that is, Linux will break up the file into strings based on separating at white space - blanks, tabs, returns). The following code will output all of the words found in $filename, each word on a separate line. for word in 'cat $filename' do echo $word done a. Write a new script, scnpt7.sh, which receives two parameters. The first is a file's name ($1 instead of $filename) and the second is a word you want to search for ($2). Inside the for loop, instead of echo $word, use an if statement to compare $2 to $word. If they are equal, add one to a variable called COUNT. Before the for loop, initialize COUNT to 0 and after the for loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions