Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this homework assignment you will be making changes to the script you created last session. Please keep the following in mind when writing a

For this homework assignment you will be making changes to the script you created last session.

Please keep the following in mind when writing a script. Do not just write Unix commands in a file and expect them to work. Two sessions ago, you figured out the commands to transform the text in raw_data to a new format. You did this by typing the commands on the command line and figuring out the commands, options and arguments to complete the task.

Last session, you took those commands and put them in a file to create a script. Trying commands on the command line and then putting them in a script will save you a lot of time when developing a new script.

This week you will take your script and incrementally make changes to it. These changes protect the user from the "Evil User" and Murphy.

Please note that you do not need the exit command to get this homework to work correctly. Do not use the exit command.

Step 1:

Execute the command CS50_hw_session09. This will create a directory called hw_session09. Inside this directory is a file called raw_data2.

Copy your script hw8.sh from the directory hw_session08 to the name hw9.sh in the hw_session09 directory. Change the comment in your script to match the name of your script for this session.

Step 2:

I want you to change your script to get the name of the file to do the text transformations from the command line. DO NOT prompt the user for the name. The first argument on the command line should be the name of the file to work on.

Example:

$ ./hw9.sh raw_data2

Do not continue until you get this step to work. Ask questions if you are having a problem.

Step 3:

Try your script without a filename as an argument.

Example:

$ ./hw9.sh

What happened? The "Evil User" or Murphy struck. We need to protect the user from themselves in this step.

Modify your script to make sure that there is an argument on the command line before using the first argument on the command line. If there are no arguments on the command line, display the error message "Please enter a filename." and exit your script.

Example:

$ ./hw9.sh Please enter a filename.

Do not continue until you get this step to work. Ask questions if you are having a problem.

Step 4:

Try your script with a filename that does not exist.

Example:

$ ./hw9.sh xyzzy

What happened? The "Evil User" or Murphy has struck again! We need to do more protection!

Modify your script to make certain that the data file you enter on the command line exists before proceeding. If you find the data file does not exist, display an error message "filename cannot be found." and exit the script. Replace the word filename with the name of the file entered on the command line.

Example:

$ ./hw9.sh xxx xxx cannot be found.

Do not continue until you get this step to work. Ask questions if you are having a problem.

Step 5:

Test your script before sending it to me to make sure it works properly. Don't just try the good cases. Try the "Evil User" and Murphy cases too.

Step 6:

Send me the file hw9.sh using the following command.

CS50_turn_in_hw hw9.sh your_email@address

Replace your_email@address with your email address. You will get a copy of what you sent me.

Let me know if you have any questions.

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

What is the purpose of the proposal?

Answered: 1 week ago