Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell script to reverse a number supplied by a user

Posted By: Daniel Evans     Category: Unix / Linux / Ubuntu     Views: 18818

Write a shell script to reverse a number supplied by a user.

Code for Write a shell script to reverse a number supplied by a user in Unix / Linux / Ubuntu

if [ $# -eq 1 ]
        then
             if [ $1 -gt 0 ]
             then
                 num=$1
                 sumi=0
                 while [ $num -ne 0 ]
                 do
                 lnum=`expr $num %  10`
                 sumi=`expr $sumi * 10 + $lnum`
                 num=`expr $num \/ 10`
                 done
                 echo "Reverse of digits is  $sumi of $1"else
                 echo " Number is less than 0"
               fi
    else
            echo "Insert only one parameter "
    fi     

--------------------------------------------------------------------------------         

output:

       $ sh1 23456
       Reverse of digits is 65432 of   23456
  
Share: 



Daniel Evans
Daniel Evans author of Write a shell script to reverse a number supplied by a user is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!