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

  Calculate the reliability of a hard disk drive

Calculate the reliability of a hard disk drive with an MTBF of 2,499 hours during the last 40 hours of this month. Assume e = 2.71828 and use the formula: reliability(t) = e -(1/MTBF)(t)

  Is anyone familiar with oracle

Is anyone familiar with Oracle 11g, 2E, Joan "Casteel Chapter5 Procedures

  What continuing education is required for the holder

what continuing education is required for the holder of a CISSP to remain current and in good standing.

  Prevent spoofing attacks by your own employees

(a) Your company will be held liable for any spoofing attacks that originate from within your network (i.e., packets leaving your network with spoofed IP header informa- tion). What can you do to prevent spoofing attacks by your own e..

  Prove the set of all functions from a to b is countable

Let A = {0,1} and B be a countable set. Prove that the set of all functions from A to B is countable

  Compute the stress and strain in a steel rod of diameter

In "C", Write a main function and the following to compute the stress and strain in a steel rod of Diameter (D) inches and length (L) subject to the compression loads P of 10,000 to 1,000,000 pounds in increments of 100,000 pounds. The modulus of ..

  Write a program keeps an appointment calendar in database

Write a program that keeps an appointment calendar in a database.

  Examine and assess the main computing problems

Use at least three (3) quality resources in this assignment. Note: Wikipedia and similar Websites do not qualify as quality resources.

  Classify each of the following occurrences as an incident

Classify each of the following occurrences as an incident or disaster. If an occurrence is a disaster, determine whether or not business continuity plans would be called into play.

  How many ascii characters can be stored

How many ASCII characters can be stored - How many different values can be stored.

  Write a program that implements binary search first using

To understand the value of recursion in a programming language write a program that implements binary search first using recursion and without recursion.

  Write a function in c language with prototype

write a function in C language with prototype.

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