I wanted to make my shell script wait infinitely
If your system supports it use:
sleep infinity
If your system doesn't support it, use sleep with a large interval:
while :; do sleep 86400; done
Note:
- Using while :in place ofwhile truemay/will remove an unnecessaryfork, depending on howtrueis implemented (built into the shell, or as a stand alone application).
You are trying to implement a busy loop, do not do this.
A busy loop will:
- Use 100% CPU for no useful purpose
- Prevent other tasks from getting CPU time
- Reduce the perceived performance of the whole system
- Use more power than necessary, especially so on systems that support dynamic frequency scaling
Why is an empty loop invalid in shell script?
Because it is... The format for a while loop in bash is as follows:
while list-1; do list-2; done
If you don't provide list-2, then you don't have a correctly formatted while loop.
As pointed out by others, use a noop (:) or anything else to satisfy list-2.
: is documented as follows:
: [arguments]
    No effect; the command does nothing beyond expanding arguments and performing any
    specified redirections.  A zero exit code is returned.