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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started