Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Shell Scripting! Part 1 Requirements The shell script srchfile.sh must accept exactly two arguments. o The script shall first print the name of the file

Shell Scripting!

Part 1

Requirements

The shell script srchfile.sh must accept exactly two arguments.

o The script shall first print the name of the file being searched.

o If there are one more instances of the string in the file, the script shall print

each line that contains the matching string, along with the line number of

the file. You may use the UNIX command grep in your script to do the

actual search. In fact, grep can even print the line number if used with

the appropriate option (see man page for grep).

If the user enters more or less than the required number of arguments, the script

shall produce an error message and stop.

The first argument shall represent the string to be searched.

The second argument represents the name of the file to be searched. If the

second argument is not a file, the script shall produce an error message and

stop.

The script must be able to execute on cs.franklin.edu

The script file name must be: srchfile.sh.

The script must be located in $HOME/itec400/homework

Make sure the permissions on the your itec400 directory are 705

Make sure the permissions on your script are 705

Sample Output

Sunny Day scenario, searching for string if in file ex0210 in examples

directory:

> srchfile.sh if /export/home/dandrear/public_html/itec400/examples/ex0210

------ File = /export/home/dandrear/public_html/itec400/examples/ex0210 ------

6:if [ "$LOGNAME" = "dandrear" ]

10:if [ "`ls | wc -l`" -ne 0 ]

14:if [ -w $PWD ]

Rainy Day scenario, script is invoked with only one argument:

> srchfile.sh if

error: must provide 2 arguments.

usage: srchfile.sh search-pattern

file

Rainy Day scenario, searching for if in a directory:

> srchfile.sh if /etc

error: second argument must be a file.

usage: srchfile.sh search-pattern file

Part 2

Requirements:

The shell script srch.sh must accept exactly two arguments. The first

argument shall represent the string to be searched.

o The second argument represents either the name of the file to be searched

or a directory. If a directory is entered, then all files in the directory shall

be searched.

o The script srch.sh shall use the script srchfile.sh to search for the

string in a given file. If the second argument is a directory, then srch.sh

will invoke srchfile.sh repeatedly in a loop.

If the user enters more or less than the required number of arguments, the script

shall produce an error message and stop.

The script must be able to execute on cs.franklin.edu

The script file name must be: srch.sh

The script must be located in $HOME/itec400/homework

Make sure the permissions on the your itec400 directory are 705

Make sure the permissions on your script are 705

Sample Output

Sunny Day scenario, searching for string then in file ex0210 in examples

directory:

> srch.sh then

/export/home/dandrear/public_html/itec400/examples/ex0210

------ File = /export/home/dandrear/public_html/itec400/examples/ex0210 ------

7:then

11:then

15:then

Sunny Day scenario, searching for string then in examples which is a

directory (search all files):

> srch.sh then /export/home/dandrear/public_html/itec400/examples

------ File = /export/home/dandrear/public_html/itec400/examples/ex0010 ------

------ File = /export/home/dandrear/public_html/itec400/examples/ex0020 ------

------ File = /export/home/dandrear/public_html/itec400/examples/ex0030 ------

------ File = /export/home/dandrear/public_html/itec400/examples/ex0040 ------

------ File = /export/home/dandrear/public_html/itec400/examples/ex0050 ------

------ File = /export/home/dandrear/public_html/itec400/examples/ex0205 ------

------ File = /export/home/dandrear/public_html/itec400/examples/ex0210 ------

7:then

11:then

15:then

.

.

.

Rainy Day scenario, script is invoked with only one argument:

> srch.sh then

error: must provide 2 arguments.

usage: srchfile.sh search-pattern

file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions