Linked Questions

1
vote
1answer
3k 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
1k 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
228 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 ...
0
votes
1answer
293 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
29 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 ...
0
votes
1answer
38 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))) ...
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
7answers
62k 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 ...
3
votes
4answers
10k 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 ...
1
vote
3answers
3k views

Shell scripting to divide numbers inside a file

I have a single column and 12 rows. Each row has numerical values. I want to divide each row values by some constant number (say C) using shell (bash) scripting. How to do this ? Thanks in advance..
4
votes
1answer
2k views

awk high precision arithmetic

I am looking for a way to tell awk to do high-precision arithmetic in a substitution operation. This involves, reading a field from a file and substituting it with a 1% increment on that value. ...
3
votes
1answer
1k views

Evaluating the return value of a command line

How do I evaluate or calculate the return value of a command line? For exemple, I count the number of lines with a grep and I want to know if that value is above X. If so, I want to print the number ...
6
votes
3answers
542 views

Attempted assignment to non-variable?

We can use arithmetic operations inside shell script function: function mess { if (( "$1" > 0 )) ; then total=$1 else total=100 fi tail -$total /var/adm/messages | more } I ...
1
vote
1answer
2k 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