Turn Your Vehicle Into a Smart Earning Asset

While you’re not driving your car or bike, it can still be working for you. MOTOSHARE helps you earn passive income by connecting your vehicle with trusted renters in your city.

🚗 You set the rental price
🔐 Secure bookings with verified renters
📍 Track your vehicle with GPS integration
💰 Start earning within 48 hours

Join as a Partner Today

It’s simple, safe, and rewarding. Your vehicle. Your rules. Your earnings.

Shell script program 2

scmuser created the topic: Shell script program 2

Use a script to take two numbers as arguments and output their sum using (i) bc (ii) expr. include error – checking to test whether two arguments were entered?

tpatil replied the topic: Re: Shell script program 2
If I understand correctly your question, You want to pass 2 parameters to shell script and print the sum of those. Also, you want to throw error if the number of parametrs are less than 2.

#!/bin/bash

if [ $# -lt 2 ]
then
echo "Usage: $0 arg1 arg2"
exit
fi

echo "\$1=$1"
echo "\$2=$2"

let add=$1+$2
let sub=$1-$2

echo -e "Addition=$add\nSubtraction=$sub\n"

Hope this helps…

renjith replied the topic: Re: Shell script program 2
#!/bin/ksh

while echo ” Enter two numbers :\n ” ; do
echo “Enter num 1: “; read A;
echo “Enter num 2: “; read B;
if [ -z $A -o -z $B ] ;then
echo ” Invalid input , pls enter again”
else
break
fi
done

export A B

echo ” ************* MENU *********** \n”
echo ” 1. cal using bc “;
echo ” 2. cal using expr”;
echo ” enter you choice :”;
read c;

case $c in
1) sum=`echo ” $A + $B “|bc` ;;
2) sum=`expr $A + $B` ;;
*) echo “invalid option , run script again”
esac

if [ $? -eq 0 ]
then echo ” Sum is $sum”
else
echo ” Script failed ”
fi

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x