Question:

Write a shell program..help guys..

by  |  earlier

0 LIKES UnLike

write a shell program that adds the 1st and 3rd arguments and multiplies the 2nd and the 4th arguments. the program also adds the product and sum. And subtract the 5th argument from the result.

sample run

$./prog 35 11 75 18 37

35 and 75 (add) --- A

11 and 18 (multiply) -----B

then A and B (add)

thanx.

 Tags:

   Report

2 ANSWERS


  1. Try

    #!/bin/bash

    let "SUM=$1 + $3"

    let "PRODUCT=$2 * $4"

    let "SUM=SUM + PRODUCT"

    let "DIFFERENCE = SUM - $5"

    echo $DIFFERENCE


  2. Try following code; it will give you desired results:

    A=`expr $1 + $3`

    B=`expr $2 \* $4`

    Part1=`expr $A + $B`

    Result=`expr $Part1 - $5`

    echo "Result is: $Result"

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.