Write a shell script named grepdir

Assignment Help Basic Computer Science
Reference no: EM13755871

1. 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.

[davis@lect1 private]$ ls
cpdirs.sh grepdir.sh makemake.sh temp temp2 temp3 uncomp.sh
[davis@lect1 private]$ grepdir.sh cpdirs.sh bin
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh .
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh cpdirs.sh bin
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh .
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh . bin
#! /bin/bash
#! /bin/bash
#! /bin/bash
bin in file 1
#! /pkg/bin/bash
[davis@lect1 private]$ grepdir.sh . bin -l
./grepdir.sh
./cpdirs.sh
./makemake.sh
./temp2/1
./uncomp.sh
[davis@lect1 private]$ grepdir.sh . BIN -l
[davis@lect1 private]$ grepdir.sh . BIN -li
./grepdir.sh
./cpdirs.sh
./makemake.sh
./temp2/1
./uncomp.sh
[davis@lect1 private]$ grepdir.sh . BIN li
usage: grepdir.sh directory pattern [-grep option]*
[davis@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
[davis@lect1 private]$

2. Write a shell script that copies the files in two directories dir1 and dir2 (supplied as the first two arguments), to dir3 (supplied as the third argument). If dir1 and dir2 contain the files with the same name, then the newer file should be copied to dir3. This does NOT look at the subdirectories of dir1 and dir2. Dir1 and dir2 must be existing directories, and dir3 may not be an existing regular file. The script should produce a usage statement if the script is misused. Name your script cpdirs.sh

[davis@lect1 private]$ ls -lR
.:
total 24
-rwx------ 1 davis users 533 2010-01-10 14:59 cpdirs.sh
-rwx------ 1 davis users 395 2010-01-10 14:39 grepdir.sh
-rwxr--r-- 1 davis users 980 2010-01-10 12:19 makemake.sh
drwxr-xr-x 2 davis users 4096 2010-01-10 15:01 temp
drwxr-xr-x 2 davis users 4096 2010-01-10 15:04 temp2
-rwx------ 1 davis users 384 2010-01-10 12:17 uncomp.sh
./temp:
total 0
-rw-r--r-- 1 davis users 0 2010-01-10 15:06 1
-rw-r--r-- 1 davis users 0 2010-01-10 14:44 2
-rw-r--r-- 1 davis users 0 2010-01-10 14:44 3.c
./temp2:
total 0
-rw-r--r-- 1 davis users 15 2010-01-10 15:04 1
-rw-r--r-- 1 davis users 4 2010-01-10 15:02 2
-rw-r--r-- 1 davis users 0 2010-01-10 14:44 3.cpp
-rw-r--r-- 1 davis users 4 2010-01-10 15:02 4
[davis@lect1 private]$ cpdirs.sh temp temp2 temp3
[davis@lect1 private]$ ls -l temp3
total 0
-rw-r--r-- 1 davis users 0 2010-01-10 15:08 1
-rw-r--r-- 1 davis users 4 2010-01-10 15:08 2
-rw-r--r-- 1 davis users 0 2010-01-10 15:08 3.c
-rw-r--r-- 1 davis users 0 2010-01-10 15:08 3.cpp
-rw-r--r-- 1 davis users 4 2010-01-10 15:08 4
[davis@lect1 private]$ cpdirs.sh temp temp2 temp3
[davis@lect1 private]$ ls -l temp3
total 0
-rw-r--r-- 1 davis users 0 2010-01-10 15:09 1
-rw-r--r-- 1 davis users 4 2010-01-10 15:09 2
-rw-r--r-- 1 davis users 0 2010-01-10 15:09 3.c
-rw-r--r-- 1 davis users 0 2010-01-10 15:09 3.cpp
-rw-r--r-- 1 davis users 4 2010-01-10 15:09 4
[davis@lect1 private]$ cpdirs.sh temp
usage: cpdirs.sh source_directory1 source_directory2 dest_directory
[davis@lect1 private]$ cpdirs.sh temp makemake.sh
usage: cpdirs.sh source_directory1 source_directory2 dest_directory
[davis@lect1 private]$ cpdirs.sh temp temp2 makemake.sh
usage: cpdirs.sh source_directory1 source_directory2 dest_directory
[davis@lect1 private]$3. (21 points) (30 minutes) Write a Bash shell script, makemake.sh, that will create a makefile called Makefile based on all the .cpp files in the current directory. If a .cpp file has any #includes of non-system header files (those with double quotes around them), then those files should be listed in its dependencies. The -Wall -ansi, and -g options will always be used with g++. The shell script takes the name of the executable as its first argument. If no argument is provided, the script should report the error, and print a usage statement. All other parameters are additional options that should be used with every call to g++. The Makefile should end with a "clean:" routine that removes the executable and all object files.

Do not use "*.o" in your clean routine. (Hints: the -n option of echo inhibits the default newline, and \t and \n work with echo. I used sed and awk to get at the name of the header files within the .cpp files.)
[davis@lect1 p2]$ ls
appointment.cpp calendar.cpp day.h dayofweek.h Lnk.c private time.h year.h
appointment.h day.cpp dayofweek.cpp Ins.c makemake.sh time.cpp year.cpp
[davis@lect1 p2]$ makemake.sh
Executable name required.
usage: makemake.sh executable_name
[davis@lect1 p2]$ makemake.sh cal.out
[davis@lect1 p2]$ make
g++ -ansi -Wall -g -c appointment.cpp
g++ -ansi -Wall -g -c calendar.cpp
g++ -ansi -Wall -g -c day.cpp
g++ -ansi -Wall -g -c dayofweek.cpp
g++ -ansi -Wall -g -c time.cpp
g++ -ansi -Wall -g -c year.cpp
g++ -ansi -Wall -g -o cal.out appointment.o calendar.o day.o dayofweek.o time.o year.o
[davis@lect1 p2]$ make clean
rm -f cal.out appointment.o calendar.o day.o dayofweek.o time.o year.o
[davis@lect1 p2]$ makemake.sh cal.out -O2 -g
[davis@lect1 p2]$ cat Makefile
cal.out : appointment.o calendar.o day.o dayofweek.o time.o year.o
g++ -ansi -Wall -g -o cal.out -O2 -g appointment.o calendar.o day.o dayofweek.o time.o
year.o
appointment.o : appointment.cpp appointment.h
g++ -ansi -Wall -g -c -O2 -g appointment.cpp
calendar.o : calendar.cpp year.h
g++ -ansi -Wall -g -c -O2 -g calendar.cpp
day.o : day.cpp appointment.h day.h dayofweek.h
g++ -ansi -Wall -g -c -O2 -g day.cpp
dayofweek.o : dayofweek.cpp dayofweek.h
g++ -ansi -Wall -g -c -O2 -g dayofweek.cpp
time.o : time.cpp time.h
g++ -ansi -Wall -g -c -O2 -g time.cpp
year.o : year.cpp year.h day.h
g++ -ansi -Wall -g -c -O2 -g year.cpp
clean :
rm -f cal.out appointment.o calendar.o day.o dayofweek.o time.o year.o
[davis@lect1 p2]$

Reference no: EM13755871

Questions Cloud

How was the communication effective : paper that applies three of the communication theories you have studied so far to your personal and/or professional life. For each theory you discuss, provide three examples of the theory at work in your life
Record the bad debts expense : Management estimates that 1% is the sales percentage to use. What adjusting entry will Hahn Company make to record the bad debts expense?
Compounding interest and the banker : There are many factors influencing the cost of money for both individuals and corporations. Suppose you deposit money in an interest bearing account and at the same time borrow a bit of money from the same bank.
Cost-volume-profit analysis : How does the firm use "Cost-Volume-Profit Analysis" to assess performance? How would you use such a system to measure how costs change as production changes? How do you develop a "break even analysis" for a given firm and how would you use it?
Write a shell script named grepdir : 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 paramet..
Financial reports required of all not-for -profits : What are the financial reports required of all not-for -profits? What additional report is required for voluntary health and welfare organization?
Research a security testing software tool : Research a security testing software tool that you practiced. Determine whether the tool would be beneficial in testing the security of a corporate network
Explain why openid offers users greater convenience : Explain why OpenID offers users greater convenience and security than the current system. Would you consider using an identity provider to access content on the Web? Why or why not
Explain the ethics of watergate and how it affected america : Explain the ethics of watergate and how it affected america.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  An analysis of the security issues associated with batch fil

For this writing assignment you will be required to provide an analysis of the Security issues associated with batch files, Visual Basic and other forms of scripting.

  What two possible ways achieve this goal to relocate

You need to relocate the existing user and computer objects in your company to different organizational units. What are two possible ways to achieve this goal?

  In what ways do the experts foresee the use

Review the literature and analyze the strengths and weaknesses of both virtualization and cloud computing in providing secure and trusted systems.

  Assignment related to excel

1. Use the "Select All" button and the "bold" buttons to bold the entire worksheet. 2. Design and create your own Company name and worksheet title 3. Enter column titles (Sales Person, Sales, Returns, Number of Items Sold, Net Sales, Sales Quota an..

  How would this ip address be expressed

How many possible hosts would there be on the above network if all usable addresses were assigned (show your work)? d. How would this IP address be expressed using CIDR notation (show your work)? e. What is the range of the block of addresses this..

  Identified users of the system

Who are the intended users and what was the main tasks that the users are expected to accomplish

  How many bits are in each part include

Label all lines and show how many bits are in each part include how number of bits for offsets, etc are calculated please.

  You have been asked to develop uml diagrams to graphically

you have been asked to develop uml diagrams to graphically depict and describe the architecture of two 2 unrelated

  Who swallowed a cat, imagine that to swallow a cat.

There was an old woman who swallowed a fly. I don't know why she swallowed that fly, Perhaps she'll die. There was an old woman who swallowed a spider, That wriggled and wiggled and jiggled inside he She swallowed the spider to catch the fly, I do..

  Level-order traversal of the red-black bst

What is the level-order traversal of the red-black BST that results after inserting the following sequence of keys:

  Database administrator's function

Primitive operations common to all record management systems include. Which of the following is a database administrator's function?

  Create an instance variable credit limit to indicate

Create another sub class CreditCustomer. Create an instance variable credit limit to indicate the maximum limit ($500). Credit customers get a markup of 2% on the order price.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd