#############################################################
# Name: sy_9
#
# Usage: ./sy_9
#
# Author: Suresh Yadagiri
# Date: August 06,2010
# Requirements:
# write a bourne shell script cv that takes the side of a cube
# as a command line argument and displays the volume of the
# cube
#
##############################################################
function printusageinfo(){
echo -e "\nUsage: $0
}
function is_integer() {
printf "%d" $1 > /dev/null 2>&1
return $?
}
if [ $# -eq 0 ]
then
echo "At least one argument expected"
printusageinfo
exit
fi
if [ $# -gt 1 ]
then
echo "only one argument expected"
printusageinfo
exit
fi
if ! is_integer $1;
then
echo -e "\nInteger argument expected"
printusageinfo
exit 1
fi
if [ $1 -lt 0 ]
then
echo "Side of cube must be positive"
printusageinfo
exit
fi
volume=`expr $1 \* $1 \* $1`
echo "Volume of cube of side $1 is : $volume"
No comments:
Post a Comment