Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this exercise, you will learn how to use a set of environment variables that are setup in a configuration script, in your main program

In this exercise, you will learn how to use a set of environment variables that are setup in a configuration script, in your main program script, so that your main script can be run without modification by users of your program. You have been provided with a configuration script a3config that is a simple text file which contains the environment variables that we will be using. The contents of this file is shown below for discussion. You can use vi to edit this file.

Your task is to write a script finder.sh that will check if there are files in the directory whose value is stored in the variable DIRNAME such that the files have the extension as indicated in the variable EXTENSION. If there are such files, you should print a list of them. Further, if the variable SHOW has the value true, the contents of the file must be displayed to screen.

In order to accomplish this, you will have to execute the contents of a3config within finder.sh. Explore the source or dot (.) commands to accomplish this. If your finder.sh script cannot find a3config, then it should throw an error message and terminate the script with a non zero exit code.

$ cat a3config # You may edit this file for your testing. # You should only change the values of the variables for the purpose of your testing # However, TAs will use their own a3config file to test your script with.

# Therefore, do not add any other code here that is required for your script's execution. DIRNAME=/tmp/__206__$LOGNAME/mydir EXTENSION=msg SHOW=true

$ ./finder.sh

Error cannot find a3config $ echo $?

2

1

The echo $? command is included above to merely show you the exit code from the script was non zero. If either of the variables DIRNAME or EXTENSION is not present in a3config or if their values are empty, the script should display an error message and terminate with a non zero exit code.

If the directory mentioned in DIRNAME does not exist, then the script should throw an error message and terminate with a non zero exit code.

If the script cannot locate any files in the directory that have the expected extension, then it should display the following message, but still terminate with a zero exit code.

If the script is able to locate files in the directory, and the value of SHOW is true then it should list the names of the files, along with the contents of each file and terminate with a zero exit code.

If the script is able to locate files in the directory, but the value of SHOW is not set to true or if the SHOW variable itself is missing from a3config, then it should list the names of the files, but do not display the contents of files and terminate with a zero exit code.

1.Your finder.sh must be executable using the bash shell in mimi.

2.(1 Point) For properly commenting throughout the source code.

3.(1 Point) Detecting and displaying an error message and terminating with non zero exit code when the script cannot find a3config.

4.(1 Point) Detecting and displaying an error message and terminating with non zero exit code when any of the variables DIRNAME and EXTENSION are not present a3config or is empty.

5.(1 Point) Displaying an error message and terminating with non zero exit code when the directory does not exist.

6.(1 Point) Displaying a message and terminating with zero exit code when the directory does exist but cannont locate any files with the expected extension.

$ ./finder.sh Error DIRNAME and EXTENSION must be set

$ echo $? 2

$ ./finder.sh Error directory /nosuchdir/dir1 does not exist $ echo $? 3

$ ./finder.sh Unable to locate any files with extension msg in /etc $ echo $? 0

$ ./finder.sh

/home/2013/jdsilv2/comp206/Mini3/first.msg Greetings to all of you! /home/2013/jdsilv2/comp206/Mini3/second.msg Howdy ? 

$ echo $? 0

$ ./finder.sh /home/2013/jdsilv2/comp206/Mini3/first.msg /home/2013/jdsilv2/comp206/Mini3/second.msg $ echo $? 0

3

7.(1 Point) Displaying only a list of files (not contents) and terminating with zero exit code when the directory does exist and is able to locate files with the expected extension, however the variable SHOW is not set in a3config or is not set to the value true.

8.(1 Point) Displaying a list of files and their contents and terminating with zero exit code when the directory does exist and is able to locate files with the expected extension, and the variable SHOW is set in a3config to the value true.

For this exercise, you should turn in the finder.sh script that you wrote.

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

f(x) = x + 1 / 4x - 2

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

How do you communicate intimacy nonverbally?

Answered: 1 week ago