![]() |
$$i and rounding
I was looking back through the threads I started and came across http://programmingforums.org/forum/s...38&postcount=6. I thought that would be more accurate, so I've been trying to construct a function that prints the fastest domain from the list of domains given to it. So far I have:
:
#!/bin/shMy problems: 1. How would I reference the argument number $i? So if $i == 2, then reference $2. Like $$i, but that's not the correct syntax. 2. What's the best way to round a number? [ complains if there are decimals passed to it. cut -d. -f1 sort of works, but it isn't the most accurate. |
Kabump.
|
1. Sorry, not familiar with bash.
2. Presuming you mean round to the nearest integer, add .5 to the number, then floor it (truncate the decimals). |
The print command line utility will round numbers.
:
z=2.111stick a :; between do and done That's a colon semicolon Finally, I don't understand what you mean by reference $i. You want to get the value of i outside the function? Or the value of the array element referenced by i - the array you declare inside the function? Note: i only has scope during the "for" loop inside the getmirror function. The array "averages" only has scope inside the getmirror function. They do not exist outside their scope. |
Quote:
:
averages[i]="$(printf "%.0f" $(ping -c 2 $mirror|tail -n1|cut -d/ -f5))"DaWei, I'll remember that for other languages. Quote:
Quote:
2. Reread #1 in the first post. (If I referenced the array element referenced by $i I'd just get the best average, not the fastest domain.) Meh, I gotta get used to going from 8 VDs to 12. Oo 100 posts! |
I've got it! $(eval "echo $""$i")
|
| All times are GMT -5. The time now is 12:52 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC