Question: Write a shell script, named grepdir.sh, that searches for a pattern in a directory, and all of its subdirectories. The starting directory is the first

Write a shell script, named grepdir.sh, that searches for a pattern in a directory, and all of its subdirectories. The starting directory is the first argument, the pattern is the second parameter, and the options for grep are all succeeding parameter(s). Options will start with a hyphen. The script should produce a usage statement if the script is misused.

[ssdavis@lect1 private]$ ls cpdirs.sh grepdir.sh makemake.sh temp temp2 temp3 uncomp.sh

[ssdavis@lect1 private]$ grepdir.sh cpdirs.sh bin usage: grepdir.sh directory pattern[-grep option]*

[ssdavis@lect1 private]$ grepdir.sh . usage: grepdir.sh directory pattern [-grep option]*

[ssdavis@lect1 private]$ grepdir.sh cpdirs.sh bin usage: grepdir.sh directory pattern [-grep option]* [ssdavis@lect1 private]$ grepdir.sh . usage: grepdir.sh directory pattern [-grep option]*

[ssdavis@lect1 private]$ grepdir.sh . bin #! /bin/bash #! /bin/bash #! /bin/bash bin in file 1 #! /pkg/bin/bash

[ssdavis@lect1 private]$ grepdir.sh . bin -l ./grepdir.sh ./cpdirs.sh ./makemake.sh ./temp2/1 ./uncomp.sh

[ssdavis@lect1 private]$ grepdir.sh . BIN -l

[ssdavis@lect1 private]$ grepdir.sh . BIN -li ./grepdir.sh ./cpdirs.sh ./makemake.sh ./temp2/1 ./uncomp.sh

[ssdavis@lect1 private]$ grepdir.sh . BIN li usage: grepdir.sh directory pattern [-grep option]*

[ssdavis@lect1 private]$ grepdir.sh . BIN -n -i 1:#! /bin/bash 1:#! /bin/bash 1:#! /bin/bash 1:bin in file 1 1:#! /pkg/bin/bash

[ssdavis@lect1 private]$

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!