Issues doing simple math in Bash script
I've been trying to find the issue for the last couple of days now and I'm apparently not processing this very well. It seems as though everytime I get an error, I fix that one and another one pops up. The only thing I can think of is that there's something I'm overlooking that would set it all straight. As stupid as the script looks, it's slightly functional for me but it's also an educational experience. Please don't suggest python or perl as a fix. There has to be a way to do it within bash.
At the time of this writing, here is the script: $downloadop is the output file from wget Code:
cat $downloadop | awk '{print $8}' | grep M | tr -d [A-Z][a-z] > tmp.txt Code:
./Speedtest.sh: line 35: 600=600000: command not found |
Quote:
Code:
avgrate=$(($a/$count)) |
You basic problem is that you don't need/want the $ in front of the left-hand variable in the = expression. Having it there causes bash to evaluate the variable and then try to evaluate the whole line. Since "408" is not a valid command, that fails.
|
Quote:
While your suggestion will undoubtedly save me some errors later, it didn't change the errors I'm currently getting where the line: Code:
$nextline=$(( $nextline*1000 )) |
$nextline=$(( $nextline*1000 ))
On a line like this, the leading $ on $nextline= is causing problems - remove that. Also, while I have not found it to seem to make a difference, the $ on variables inside $(( )) evaluations is not needed. So: Code:
nextline=$(( nextline*1000 )) |
Quote:
Code:
+ cat /home/buee/Desktop/OutputFile.txt Here's the code just to make sure I didn't understand correctly: Code:
cat $downloadop | awk '{print $8}' | grep M | tr -d [A-Z][a-z] > tmp.txt |
Code:
kilos=(( $kilos * 1000 )) So: Code:
kilos=$(( kilos * 1000 )) |
Quote:
Quote:
|
Quote:
Anyway, here's the newest script: Code:
#!/bin/bash |
Wget reports in KB/s, which is KBytes. I get this line running a similar speed test as you do:
Code:
2010-07-21 00:00:50 (470 KB/s) - `/home/jlinkels/reference.pdf' saved [23510720/23510720] Run your script with sh -x yourscript, and much will become clear about where errors are made. When I have to do calculations in Bash scripts which go beyond a simple addition, I use dc. Example: Code:
result=$("echo 12 14 * 3 / p" | dc) Finally, I would propose you do not use a Linux site for speed tests. I have done so as well until I realized that I was just eating up bandwidth mostly from non-profit organizations. I use this link for speed testing: :) http://download.microsoft.com/downlo...a/dotnetfx.exe jlinkels |
Quote:
Code:
#!/bin/bash The first few lines are self explanatory The line with seemingly random numbers is the sum of all speeds added together and the number of lines in the file The first time (military) is when the whole script starts The second time " " is when the download finishes and the calculations begin The third time " " is when the whole process completes Code:
This is with Ubuntu Distro, all lines calculated |
All times are GMT -5. The time now is 08:25 AM. |