Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions

Question

PowerBI uses M - code to change visualizations directly True False

Answered: 1 week ago