Linked Questions

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
620 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
1answer
45 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 ...
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
3
votes
4answers
35k 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 ...
2
votes
4answers
6k 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
2k 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..
3
votes
1answer
715 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
216 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 ...
6
votes
1answer
276 views

What is the rationale for the bash shell not warning you of arithmetic overflow etc.?

There are limits set for the arithmetic evaluation capabilities of the bash shell. The manual is succinct about this aspect of shell arithmetic but states: Evaluation is done in fixed-width ...
2
votes
4answers
201 views

How to divide the output of one command by the output of another?

I would like to know the server load divided by the amount of CPU cores in order to judge which servers are overloaded. I can get the amount of CPU cores with: $ grep -c processor /proc/cpuinfo 2 I ...
1
vote
3answers
58 views

I want to divide a sum of numbers by a value

So here is my code for Unix shell scripting #! /bin/ksh echo "Enter your first number:" read first echo "Enter your second number:" read second echo "Enter your third number:" read ...

15 30 50 per page