4
votes
4answers
14k views

Perform floating point arithmetic in shell script variable definitions [duplicate]

I understand bash and some other interpreters only perform arithmetic for integers. In the following for loop, how can I accomplish this? I've read that bc can be used but am not sure how to use bc ...
2
votes
1answer
10k views

Divide a variable by a number? [duplicate]

Basically I need to convert centimetres to inches which I am trying to do by diving the area in centimetres by 2.54. But I just cannot get this to work. echo "please enter width and then height" ...
0
votes
2answers
2k views

Re-assigning (specifically, incrementing) a variable in a bash script [duplicate]

Possible Duplicate: How can I do command line integer & float calculations, in bash, or any language available? I would like to simply re-assign a variable (to be specific, increment it ...
1
vote
1answer
2k views

Trying to multiply a float in bash not working [duplicate]

I have this script that is to rescale images to a percentage value #!/bin/bash percent=$1 echo $percent for img in `find *.png`; do echo Processing file $img width=$( mdls $img | grep ...
1
vote
1answer
1k views

How can subtract 2 floats which have been extracted from 2 other files with BASH [duplicate]

I'm trying to get the difference between two numbers which I have taken from two files. I think my code will make sense: I've tried to make it work by two different methods, didn't work. What I get ...
2
votes
1answer
174 views

Is it possible to get a decimal output from doing division in Bash? [duplicate]

Basically in Bash, what I'm trying to do is take a input of seconds from a user and find the hours. So basically if the user enter 35 the output should be 0.00972222. But bash gives me is a zero. ...
2
votes
1answer
130 views

bash + how to calculate very long numbers in bash? [duplicate]

how to calculate very long numbers in bash? param=$(( 3247238523785623478565 + 53453453252345346534563412634 )) echo $param 3420247196502465471 as we see here this isnt the right answer , because ...
1
vote
2answers
311 views

Copy Single Value from a file to a variable and perform arithmetic over it? [duplicate]

Suppose we have a file like 'abc.txt' which has a single value 123456 and file 'xyz.txt' which also has a single value like 654321. I want to store these values form the file to some shell variable ...
0
votes
1answer
207 views

integer number division to decimal number in bash script [duplicate]

in bash script i have to change the value of $R , so i have to division to decimal number but it's impossible R=$((R/(15.6))) #for convert move in millimeter to second i try to R=$((R/(156/10))) ...
1
vote
1answer
95 views

How to do float operation in Shell script? [duplicate]

time_value=$(($large / 1000)) $large could be 60 or 57. I'm expecting 57/1000=0.057. But I'm getting 0. So, is there any way to do this?
0
votes
1answer
39 views

If else statement involving two numbers in scientific notation [duplicate]

I have two numbers in scientific notation and I want to do some comparison between them in an if statement in bash. While doing so, I am getting error like bwlow: E.g: bash-4.2$ a=10e-12 bash-4.2$ ...
0
votes
0answers
20 views

Multiply 2 array index variables shell programming [duplicate]

How do i multiply 2 array index variables given the following foo=(1 2) bar=(0.1 0.2) foobar=$((foo[1]*price[1])) # this is wrong echo "$foobar" Current output : 0 Correct/Expected output : 0.4
2
votes
8answers
128k views

Adding two numbers using expr

I'm learning Shell scripting for a diploma in IT I'm currently doing. I'm trying to write a small script that adds two numbers as shown as in one of the tutorials we were given. echo "Enter two ...
5
votes
4answers
19k views

Calculate variable, and output it to another variable

The only calculator I know is bc. I want to add 1 to a variable, and output to another variable. I got the nextnum variable from counting string in a file: nextnum=`grep -o stringtocount ...
2
votes
1answer
11k views

How to round floating point numbers in shell?

How do I correctly round IEEE 754 floating point numbers on the command line? I want to specify the precision of the output number - the count of fractional digits. Rounding 6.66 to precision 1 ...

15 30 50 per page