Wednesday, July 17, 2013

write a script that takes two integer command line arguments.the script displays the numbers between the two integer (including the number) in asscending order if the first number is smaller than the second and in descending order if the first number is greater than the second. Name the script count_up_down

#!/bin/bash
############################################################
# Name: sy_5
#
#
# Usage: ./sy_5
#
# Author: Suresh Yadagiri
# Date:  August 06,2010
#
# Requirements:
# write a script that takes two integer command line arguments.the script
# displays the numbers between the two integer (including
# the number) in asscending order if the first number is
# smaller than the second and in descending order if the
# first number is greater than the second. Name the script
# count_up_down
#
############################################################

function printusageinfo(){
echo -e "\nUsage: $0 \n"
}
function is_integer() {
    printf "%d" $1 > /dev/null 2>&1
    return $?
}
if [ $# -eq 0 ]
then
        echo "Two arguments expected"
        printusageinfo
        exit 1
fi
if [ $# -gt 3 ]
then
        echo "Too many arguments "
        printusageinfo
        exit 1
fi

if ! is_integer $1 -o  ! is_integer $2;
then
        echo -e "\nInteger arguments expected"
        printusageinfo
        exit 1
fi

number1=$1
number2=$2

#echo " $number1  $number2"

if [ $number1 -lt $number2 ]
then
   until [ $number1 -eq $number2 ]
   do
      echo " $number1 "
      number1=`expr $number1 + 1`
   done
  echo " $number1 "
exit 0
fi

if [ $number1 -gt $number2 ]
then
   until [ $number1 -eq $number2 ]
   do
      echo "$number1"
      number1=`expr $number1 - 1 `
    done
    echo "$number1"
exit 0
fi

echo " Numbers are equal "
exit 0

2 comments:

  1. TINNED PECHNIC AT VINTAGE PECHNIC AT VINTAGE PECHNIC AT
    Titanium Chunky PECHNIC AT titanium wedding bands VINTAGE titanium bracelet PECHNIC AT VINTAGE titanium fat bike PECHNIC AT VINTAGE PECHNIC AT VINTAGE PECHNIC AT VINTAGE titanium stud earrings GARDENS, 2-in-1 titanium tv apk 3in-2

    ReplyDelete