Linked Questions

11 votes
4 answers
82k views

how to calculate percentage from number for example we set number=248 and we want to know what is the 80% from $number so how to calculate it in bash ? expected output 198 ( exactly is 198.4 but ...
yael's user avatar
  • 14k
14 votes
2 answers
23k views

I have read that bash can do integer arithmetic without using an external command, for example: echo "$((3 * (2 + 1)))" Can bash also do floating-point arithmetic without using an external command?
user267288's user avatar
5 votes
4 answers
23k views

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 ...
John B's user avatar
  • 626
9 votes
1 answer
41k views

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. ...
shawn edward's user avatar
3 votes
1 answer
17k views

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 ...
3kstc's user avatar
  • 5,062
12 votes
1 answer
8k views

How to calculate very long numbers in bash? param=$(( 3247238523785623478565 + 53453453252345346534563412634 )) echo $param 3420247196502465471 as we see here, this isn't the right answer because of ...
maihabunash's user avatar
  • 7,231
1 vote
4 answers
10k views

Let's say I have a variable and I want to print 5 significant digits after I multiplied it by 1000. zsh can do it: zsh$ x=2.8026407e+00 zsh$ printf "%.5g\n" "$(( 1000*${x} ))" zsh> 2802.6 Can bash ...
pfnuesel's user avatar
  • 6,293
3 votes
1 answer
30k views

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" ...
Strobe_'s user avatar
  • 445
4 votes
1 answer
22k views

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 ...
Duck's user avatar
  • 4,814
3 votes
4 answers
4k views

I need to sum numbers from a file line by line. The file: 1.0 0.46 0.67 I want to sum, then divide 3. I currently have: while IFS= read -r var do x=$(($var + $x)) | bc -l done < "file.txt" ...
Melih's user avatar
  • 147
0 votes
2 answers
8k views

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 by 0....
Andrew's user avatar
  • 17.8k
4 votes
1 answer
7k views

I have been doing integer calculation like this. a=12 b=23 c=$((a-b)) echo $c But, now for float numbers its is failing i read that we can do that using bc however i want to assign the result in ...
Avitesh Kesharwani's user avatar
0 votes
2 answers
2k views

Hi I have to divide two numbers in #!/bin/sh $x = 5678 $x/1000 but calculations return only integer: 5. I need 5,678. I've tried $x/1000.0 $x/1000.0 | bc on first method expect integer second ...
user22090909's user avatar
1 vote
1 answer
3k views

#!/bin/bash x=1 while [ "$x" -lt 20 ] do echo "$x" x=("$x" * 5); done Getting error as syntax error near unexpected token `done' and getting output as 11111111111....
raju kiran's user avatar
5 votes
1 answer
1k views

My shell is bash and I have three variables x=5; y=7; z=7.5 I am trying to use the below statement to test the equality of variables $y and $z as shown below Command: test $z -eq $y; echo $? But, it ...
AngiSen's user avatar
  • 207

15 30 50 per page
1
2 3 4 5