Click to See Complete Forum and Search --> : bash scripting help


talha999
05-09-2004, 06:40 PM
here is simple script which is take input and divide value by 10

but the problem it is not showing answer in decimals

like i put 55 it shows 5 which should be 5.5

Regards

#!/bin/bash
echo -n "Enter the value of a:"
read a
b=$[$a / 10]
echo $b

go_away
05-09-2004, 06:58 PM
i honestly do not know how to divide with bash, as i have always just used bc

it too will truncate unless you set the scale variable

try this:

[code]
#!/bin/bash
echo -n "Enter the value of a:"
read a
b=`echo "scale=10; $a / 10"|bc`
echo $b
[code]

bsh152s
05-09-2004, 07:41 PM
bash does not do floating point arithmetic. talha999 is correct in that you need to use bc.

talha999
05-09-2004, 10:24 PM
Thanks for your replys ! bc works fine


Regards