Introducing UNIX and Linux |
More on shellsOverview |
Answer to chapter 8 question 1This is an exercise in arithmetic expansion only. printf "Enter cm: " # Prompt read CM # Read number of cm FEET=$(( $CM / 30 )) # Feet is easy to calculate CM=$(( $CM % 30 )) # Replace CM by residual cm # above the previous feet INCHES=$(( $CM * 12 / 30 )) # Convert residual cm # to inches printf "%d cm is %d foot %d inches\n" $CM $FEET $INCHES |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck