PDA

View Full Version : [SOLVED] Bash while loops with no commands



lavinog
July 30th, 2008, 08:41 PM
I am wondering if there is a way to get a bash while loop to loop without any commands between do and done, or is there some sort of dummy command that isn't evaluated.
The best I can come up with is to use true (see below example)



time $(count=50000;while [ $count -gt 0 ]; do let --count; done)
real 0m1.735s
user 0m1.692s
sys 0m0.040s

time $(count=50000;while [ $[ count-- ] -gt 0 ]; do continue; done)

real 0m1.768s
user 0m1.716s
sys 0m0.056s


time $(count=50000;while [ $[ count-- ] -gt 0 ]; do true; done)
real 0m1.667s
user 0m1.624s
sys 0m0.048s


I know that bash isn't meant for speed, and there are simpler ways to count. I will be using a similar command for getting positions in arrays

tamoneya
July 30th, 2008, 08:42 PM
just put a "sleep" in there.

sisco311
July 30th, 2008, 08:54 PM
try:
time $(count=50000;while [ $[ count-- ] -gt 0 ]; do : ; done)

ghostdog74
July 31st, 2008, 01:50 AM
I know that bash isn't meant for speed, and there are simpler ways to count. I will be using a similar command for getting positions in arrays
what exactly are you wanting to do ? describe more clearly.

lavinog
July 31st, 2008, 04:19 AM
Thanks sisco311,
That was exactly what I was looking for.