I'm using zsh, and I have this function:
function timer-raw() {
# Just think `loop fsayd` is `echo hi` for the purposes of this question.
eval "sleep $((($1)*60))" && eval ${(q+@)@[2,-1]:-loop fsayd}
}
Andtimer-raw's first argument tells it how many minutes to wait; The rest of the arguments, if present, would be evaled as if typed on the command line, after the wait:
timer 3 echo sth
# After 3 minutes, echoes `sth`.
However, if no further arguments are supplied, I want it to run the default command loop fsayd:
timer 4
# runs `loop fsayd` after 4 minutes
The problem is that I want loop fsayd to be substituted as two words, but I don't know how. I tried these variations, too, but they didn't work either:
"${(q+@)${@[2,-1]:-loop fsayd}}"
"${(q@)${(q@)=@[2,-1]:-loop fsayd}}"
"${(qq@)=@[2,-1]:-loop fsayd}"
By "didn't work", I mean either a simple timer 0 would fail by a command not found, or that timer 0 ff hi 'man hi jk k' failed to return the correct number of input arguments. (ff() echo "$#")
Note: I do not want to use test -z "${@[2,-1]}".