This works fine (infinite loop):
$ while TRUE; do printf ".";done
.............................................................................
I am trying to timeout this while loop
with the timeout
command.
All these don't work:
$ timeout 5 while TRUE; do printf ".";done
$ timeout 5 "while TRUE; do printf ".";done"
$ timeout 5 "while TRUE; do printf \".\";done"
$ timeout 5 $(while TRUE; do printf ".";done)
$ timeout 5 $('while TRUE; do printf ".";done')
What is the correct way (if it exists)?
I think that the solution to your problem is to execute another shell instance and pass proper commands to it. According to bash manual:
Thus my solution would be something like that:
--
assures that the following arguments will be treated as non-option. And''
helps with passing"
without unnecessary escaping