Question
Write a bash shell script named path.sh that takes an even number of arguments (four or more). These arguments are (x, y) pairs that represent
Write a bash shell script named path.sh that takes an even number of arguments (four or more).
These arguments are (x, y) pairs that represent points in a path. That is: path.sh x1 y1 x2 y2 ... xn yn where x1, y1, ... xn, yn are integer values that make up the points (x1, y1) to (xn, yn)
Your script will calculate the following based on this input: The total length of the path. The longest distance between two consequent points in the path The average distance between two consequent points If the path leads exactly back to the start, if not the distance between the starting point and ending point.
Each calculation should be done with 2 decimal points of precision and the output for each length should be a real number with 2 decimal points of precision.
Your script should contain error checking and exit with an appropriate exit status and error message when an error is encountered. You should check for the following errors at a minimum: If the script is given less than four arguments. If the script is given an odd number of arguments. If any argument to the script is not an integer value.
In the event of an error the only output should be your error message and not any errors from other commands. For example, if there is an invalid integer your script should not output something like \-bash: test: cat: integer expression expected".
You should include a comment at the beginning of the le (under #!/bin/bash) that contains your name, student number and a one or two sentence description of what the script does. Also add at least two comments to lines in your script explaining what they do.
Hints
You can test if a number is an integer using the test command. The test command will return an exit status of 2 if you attempt to use a non-integer with an operation like -eq. You can read the exit status of the last command with $?.
The test command can not compare real values, but the bc command can and you can use it's output with test.
The equation to nd the distance between two points is:
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