Question: 5. Write the following script calling it script5 #1 /bin/bash read -p Enter the number you seek NUM for VALUE in $e do if [
5. Write the following script calling it script5 #1 /bin/bash read -p "Enter the number you seek NUM for VALUE in $e do if [ $VALUE-eq $NUM ]; then COUNT=$( (COUNT+1)); fi done echo NUM appeared $COUNT times Run script5 passing it the list of numbers 5 10 6 12 5 18 10 4 19 21 5 12 18 22 and when prompted, input 5. Rerun the script inputting 18 instead. Rerun the script inputting 23 instead. What outputs did you get for each input? 6. Rewrite the script in #5 to input two inputs instead of just NUM and count the number of parameters that fall between the two. For instance, if the input is 10 and 20, we would have 5 matches (12, 18, 19, 12, 18). 7. Write a script that receives a list of parameters and output the largest and smallest of the list. If the user does not pass any parameters, output an error message. Test out your script to make sure it works in a variety of cases (no parameters, 1 parameter, 5 parameters, etc) 8. Enter the following script into vi, calling it script8 #1 /bin/bash for file in $@ do if [ -r $file && $file &&-x $file 11 then count-(count+1)) fi done echo of the $# files entered, $count were r/w/x Run the script to make sure it works. Modify the script in three ways: 1. 2. 3. output an error message if no parameters are supplied rather than counting the number of files, add up the size of these files Output the average size of the file (which will be the sums 9. Write a script which receives a directory name and iterates through all of the items in this directory, counting the number of items that are regular files, that are directories, and that are links, and output this result along with the total number of items being reported on. Run your script on several directories like letc, /bin and-. 10. Write a script which receives a list of strings as parameters. Input an "index string". Iterate through the list of strings and apply the expr index. operation on each string using the index string as the index (see chapter 7 for more information about how expr index works). Output the string and the result of the index operation. When done, run it passing the string abacab foxtrot duke trespass and input the index string of abed. Your output should be abacab 1, duke, foxtrot 0, trespass 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
