Saturday, January 14, 2012

Shell Script to find the sum of two numbers supplied as command line argument


Q. How do I add command line arguments in Bash
Ans:

#!/bin/bash
if [ $# -ne 2 ] ; then
echo -e " please provide correct number of arguments"
else
# $1 is first argument and $2 is second .
echo " sum of $1 + $2 is `expr $1 + $2` "
fi

Output

Enjoy :)

0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.