14 January 2012

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

2 comments

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


how to add command line argument in bash

Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

2 comments:

  1. Please give some explanation with commands

    ReplyDelete
  2. Great explanation. please check our website at https://www.techcarbasa.com/

    ReplyDelete