The traditional system of measurements, as used in the U.S.A., is the best! It’s so simple to understand! “meters”—who needs ’em? We have yards, furlongs, miles, and leagues! ☹
In this assignment, you will write a bash script called
unity which will do some length conversions. Specifically,
it will recognize these units:
| Unit | Conversion |
|---|---|
| inches | |
| hands | 4 inches |
| feet | 12 inches |
| yards | 3 feet |
| furlongs | 220 yards |
| miles | 5280 feet |
| leagues | 3 miles |
| au | 92,955,807 miles |
You only have to recognize those names, which are all plural. You don’t have to recognize “foot” or “mile”. No other units (meters, angstroms, light-years, etc.) should be recognized.
% ./unity 4 feet as inches
4 feet = 48 inches
% ./unity 10 miles as feet
10 miles = 52800 feet
% ./unity 17 furlongs as furlongs
17 furlongs = 17 furlongs
% ./unity 3 yards as feet
3 yards = 9 feet
% ./unity 10 feet as yards
10 feet = 3 yards
% ./unity 1 au as inches
1 au = 5889679931520 inches
% ./unity
usage: ./unity <number> <units> as <units>
% ./unity XYZ inches as feet
usage: ./unity <number> <units> as <units>
% ./unity 1X inches as feet
usage: ./unity <number> <units> as <units>
% ./unity 1 inches as feet extra stuff here
usage: ./unity <number> <units> as <units>
% ./unity 3 yard as feet
Unrecognized unit: yard
% ./unity 1 feet as meters
Unrecognized unit: meters
Your program will convert between all pairings of those units. That is, the second and fourth arguments can be any of the recognized units.
bash script, and not use any other
languages such as perl, awk, or csh.
expr or grep.
#! /bin/bash
How to receive negative points: