I want to write a "forever" function that I can run multiple commands until I manually kill it with Ctrl-C. Basically, from the zsh command line, I know I can do this, and this works fine:
$ while {} { ls ; sleep 1 }
which will repeated call ls
and sleep 1
, forever.
I can't figure out a syntax to turn something like that into a function. Something like:
forever() { while {} { "${@}" } }
which I want to then then call with something like:
$ forever ( ls ; sleep 1 )
It probably seems silly when while {} {<commands>}
and forever {<commands>}
is hardly very different.
But what I really want as my end goal is a "forever-sleep" function, where I can say something like
$ forever-sleep 5 ls -l
$ forever-sleep 5 ( ls -l a ; ls -l b )
and it will sleep $1
seconds after executing the command(s) I give it, forever (until I manually kill it with Ctrl-C).
(I've tried lots of combinations and nestings of ()
,(())
,{}
,[]
,[[]]
,""
,''
, and such, and I just can't figure out how to get both the function and the command line not to have syntax errors, parse errrors, etc.)
So,
- Is there something similar to this "forever" idea already?
- Is this possible in a function? (I would prefer a function I can put in my
.zshrc
rather than having a separate executable shell script.)