lunedì 5 marzo 2012

Arithmetic calculation on real numbers in Ksh Script

Today a simple program to execute arithmetic calculation with ksh script :

#!/bin/ksh
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 "scale=3\n(($price * $per) / 100)" | bc -l`
echo $sav

Is important see this command :

sav=`echo "scale=3\n(($price * $per) / 100)" | bc -l`

With "scale=3" we are fixing number of decimals to print.
With "bc -l" we are calculating with unix command bc the discout applied, with
($price * $per) / 100.

Stay tuned.


Dice simulator

Today a simple shell script to simulate rolls of two dices :

#!/bin/ksh

fc=1

while [ fc -eq 1 ]; do

clear

echo ' How many rolls : \c'
read times

ind=1
while [ $ind -le $times ]; do

echo 'Roll Dice ' $ind
dice1=$RANDOM
dice2=$RANDOM

echo 'dice1 :' $(( dice1%6+1 ))
echo 'dice2 :' $(( dice2%6+1 ))

ind=$(( $ind + 1 ))
done

echo ' Continue(y/n) : \c'
read ans

if [ $ans = 'N' ] || [ $ans = 'n' ]; then
fc=0
fi

done


Stay Tuned.

Check first quarter 2024

 Hi all Today, 1st May I'll check my 2024 goals. This is the first time I check it. For me it's a good way to reach more objective p...