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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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