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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started