Welcome, Guest
Username Password: Remember me

Shell script that will add two nos
(1 viewing) (1) Guest
Shell Script
  • Page:
  • 1

TOPIC: Shell script that will add two nos

Shell script that will add two nos 9 months, 2 weeks ago #682

  • rajeshkumar
  • OFFLINE
  • Moderator
  • I love software configuration management
  • Posts: 370
  • Points: 44590
  • Karma: 4
  • Honor Medal 2009
How to write shell script that will add two nos, which are supplied as command line argument, and if this two nos are not given show error and its usage

<code>
#!/bin/bash
#
# Linux Shell Scripting Tutorial 1.05r3, Summer-2002
#
# Written by Vivek G. Gite < This e-mail address is being protected from spambots. You need JavaScript enabled to view it >
#
# Latest version can be found at www.nixcraft.com/
#
# Q1.Script to sum to nos
#

if [ $# -ne 2 ]
then
echo "Usage - $0 x y"
echo " Where x and y are two nos for which I will print sum"
exit 1
fi
echo "Sum of $1 and $2 is `expr $1 + $2`"
#
# ./ch.sh: vivek-tech.com to nixcraft.com referance converted using this tool
# See the tool at www.nixcraft.com/uniqlinuxfeatures/tools/
#

</code>
Regards,
Rajesh Kumar
Build and Release Engineer
My Blog: community.scmgalaxy.com/pg/profile/rajeshkumar
  • Page:
  • 1
Time to create page: 0.57 seconds

     
    
Home Forum