0% found this document useful (0 votes)
66 views1 page

Shell Script

This shell script adds two numbers passed as command line arguments. If two arguments are not provided, the script displays an error message stating the correct usage is to pass two numbers and prints their sum. If two numbers are passed, it calculates and displays the sum of those numbers.

Uploaded by

KuldeepMis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views1 page

Shell Script

This shell script adds two numbers passed as command line arguments. If two arguments are not provided, the script displays an error message stating the correct usage is to pass two numbers and prints their sum. If two numbers are passed, it calculates and displays the sum of those numbers.

Uploaded by

KuldeepMis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Q.1.

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
A.
#
#
#
#
#
#
#
#
#

#!/bin/bash

Linux Shell Scripting Tutorial 1.05r3, Summer-2002


Written by Vivek G. Gite <[email protected]>
Latest version can be found at http://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`"
#

You might also like