Reputation: 5555
Hi I want to write and empty body loop. I just want the loop counter to increment so I want the cpu to stay busy without any IO operation. Here is what I have written but it gives me an error:
#!/bin/bash
for (( i = 0 ; i <= 1000000; i++ ))
do
done
root@ubuntu:~# ./forLoop
./forLoop: line 4: syntax error near unexpected token `done'
./forLoop: line 4: `done'
Upvotes: 16
Views: 12204
Reputation: 42870
You must specify at least one command in a loop body.
The best command for such a purposes is a colon :
, commonly used as a no-op shell command.
Upvotes: 32
Reputation: 58447
You could use sleep x
if you want to delay for x number of seconds.
Upvotes: 0
Reputation: 72755
You could put a no op command inside the loop like true
or false
(do nothing successfully or unsuccessfully respectively).
This will be a tight loop and will burn CPU. Unless you want to warm up your computer on a cold morning, you can simply say i=1000000
and have the same effect as the loop.
What is it that you're trying to achieve?
Upvotes: 4