Question

Copy/Paste your script from 5b here.

4. Lets look at a more complicated script executable. a. Write the following as script6.sh and change its permissions to count for num in d do if num eq 100 then count (count+1) done echo The number 10 was found $count times What is the output? Run the script as ./script6.sh 10 20 30 10 40 20 50 10 60 <enter Summarize what the script does r using the read command. The following script inputs bl Values can be input b information from the user and outputs it /bin/bash. Enter your name echo read name echo Hello $name that Note that the -n in the echo statement forces echo to not output a new line character s 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 users 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 5. 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 echo $word. done Write new script, script7.sh, which receives two parameters. The first a files name ($1 $filename) and the second is a word you want to search for ($2) instead of nside the for loop, instead of echo word, use an if ement to compare $2 to $word. If they are equal, add one to a variable COUNT. Before the for loop, initialize COUNT to o and after the for loop

0 0
Add a comment Improve this question Transcribed image text
Answer #1

5 b)

#!/bin/bash

args=$#
count=0
if [ $args -gt 1 ]
then
        for word in $(cat $1)
        do
                if [ $word == $2 ]
                then
                        count=$((count +1))
                fi
        done
                printf "Total : "$count" Words !!\n"
else
        printf "Wrong Arguments\nUsage : "$0" arg1 arg2\n"
fi

Add a comment
Know the answer?
Add Answer to:
Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

  • LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script,...

    LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script, we will iterate through all files in the current directory print out their name using the for loop. Example (do not type yet): foriin*;do …;done where the…does some operation on$I, which stands for the current file. To do this, enter the following in your script4.sh file:           #!/bin/bash           for i in *; do                echo $i           done Once the above works, change the for loop to...

  • Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment...

    Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment to tell us what you did, why and how. 3. allows a user to enter their name and a number between 1 than 100 (this must be prompted so the user knows what to do) 4. creates a random number between 1 and 100 for you to guess. The command to create a random number is shown below. (if you find a better one...use...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • 1. Write 4 simple shell scripts. Each question will ask you to write one or more...

    1. Write 4 simple shell scripts. Each question will ask you to write one or more command lines to solve a problem. Put the command(s) from each problem into a file named problem1.sh, problem2.sh Note that if you want your script to be interpreted by bash, each file should start with the line: #!/bin/bash and will have one (or more, as needed) commands following it. To execute each script in bash, so you can determine if it is working or...

  • Please answer 1c, use MATLAB, and paste your entire script in your answer so that I...

    Please answer 1c, use MATLAB, and paste your entire script in your answer so that I can copy and paste to see if it works. Problem #1 400g triangle square pentagon hexagon Figure 1 For a closed geometric figure composed of straight lines (Figure 1), the interior angles in the figure must add to (n-2)(180) where n is the number of sides. Required Tasks a) Write a script that prompts the user to select from one of the following shapes:...

  • 3 Programming Question (45 points) 3.1 Instructions You need to write the code by yourself. Your...

    3 Programming Question (45 points) 3.1 Instructions You need to write the code by yourself. Your implementation must use C/C++ and your code must run on the Linux machine general.asu.edu. Please refer to the programming guide (available under the Assignments folder on Blackboard) for using the general.asu.edu server, as well as compiling and running C/C++ code under Linux For this question, you need to provide a Makefile that compiles your program to an executable named a3 that runs on the...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

  • Explain everything that is happening on line 125 of the script, where the roff2pdf() function is called. (Hint: sort out the function arguments and input/output redirection.) line 125: roff2pdf "$...

    Explain everything that is happening on line 125 of the script, where the roff2pdf() function is called. (Hint: sort out the function arguments and input/output redirection.) line 125: roff2pdf "$OUTPUT_TITLE" < $TMP_FILE_M > $OUTPUT_FILE #1 /bin/sh # Verify that the command line arguments are suitable if [ -z "$1" ] 11 [ $# -gt 2 ]; then echo "Usage: $0 <page> [<section>]" exit 1 1 # util is avail # Check whether a utility is available on the system. #...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT