Shell Script To Add Two Numbers Using Command Line Arguments - The Coding Shala

Home >> Scripting >> Add two numbers

Shell Script To Add Two Numbers Using Command Line Arguments

Write a shell script to add two numbers supplied as a command-line argument?

Code: 

#!/bin/bash
if [ $# -ne 2 ] 
then
echo "enter two arguments"
else
sum=$(echo "$1 + $2" | bc)
echo "$sum "
fi



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

InterviewBit - Colorful Number Solution - The Coding Shala