I am begining to learn bourne shell and as a practice I have written a script which when given the purchase price and percentage of discount calculates the savings.
I somehow cannot figure out why my script fails to do arthimatic calculation on real numbers.
Could anyone look at the script and recommend where is the flaw.
Thanks in advance
#!/bin/sh
echo "Enter the Price of the item \$ \c"
read price
echo "What Percentage of discount is available \c"
read per
echo "Your Total Savings are \c"
sav=`expr \( $per / 100 | bc -l \) \* $price`
echo $sav
What does your current script look like?
What happened when you ran it?
What answers did you give to the questions?
Complete modified script. Only calculation line has changed. I have just tried it in Bourne Shell, Korn Shell and Posix Shell.
#!/bin/sh
echo "Enter the Price of the item \$ \c"
read price
echo "What Percentage of discount is available \c"
read per
echo "Your Total Savings are \c"
sav=`echo "(($price * $per) / 100)" | bc -l`
echo $sav