Question: testSearch.sh: #!/bin/bash # a simple script to count the number of items (files and subdirectories) in any given directory. # The script takes one command

 testSearch.sh: #!/bin/bash # a simple script to count the number of

testSearch.sh:

#!/bin/bash

# a simple script to count the number of items (files and subdirectories) in any given directory.

# The script takes one command line arugment.

#input: a directory name on the command line, which should be either an absolute path (eg. /home/student) or relative path (eg. ../music)

#output: the number of items (both files and subdirectories) in the specified directory

if [ -z $1 ]; then

echo "usage: " $0 ""

exit

fi

num_items=0

for entry in "$search_dir"$1/* #if $1 is a directory name, we can also write this line as: for entry in $1/*

do

#echo "$entry"

((num_items = num_items + 1)) #entry will iterate through all the items in the specified directory; all we need to do is increment our counter variable num_items for each iteration

#num_items=$[$num_items+1] #this works

#let num_items=$num_items+1 #this works

#let num_items=num_items+1 #this works

done

echo "total number of items in directory $1:" $num_items

Modify the testSearch.sh script into A6p1.sh to output the number of files and subdirectories separately in the directory that is specifiled as the first commandline argument to the script. Do not count recursively in subdirectories. (15 points) (Script will be tested using "A6p1.sh

" where can be any absolute (those starting with/) or relative directory (those not starting with ).) Your output can look like: Number of files in 12 Number of subdirectories in : 5

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!