Question: Background: Here's a small shell script that compares two files: #!/bin/sh # compare f1 f2 # script to compare and comment on differences between 2

Background: Here's a small shell script that compares two files:

 

#!/bin/sh

# compare f1 f2

# script to compare and comment on differences between 2 files echo comparing $1 with $2

if diff $1 $2; then

echo true

else

echo false

fi

If you store this script in a file called compare and make that file executable with chmod +x compare, you can run it with ./compare f1 f2 for any 2 files f1 and f2. (Try it with small files.) Note, in the script, $1 is a reference to the first command line argument, and $2 is a reference to the second. This is really bad language design, but it works, so we live with it.

a) Does the diff command return an idication of success or failure? If so, when does it indicate success and when does it indicate failure. The above script lets you test this empirically. (0.5 points)

b) Suggest a script that could be used in the test script in order to allow each test to be coded on one line, assuming that there were existing files holding the input, the expected output, and the expected error messages for each test, stored in the testfiles directory. (0.5 points)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!