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}
}
timer-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]}".
if [ check_that_your_variables_are_defined ] ; then eval your_variables ; else loop fsayd ; filoop fsaydis a very simple command that can be substituted byecho hiif you want to test it yourself. The problem is that it needs to be substituted as"loop" "fsayd"but it is substituted as"loop fsayd"which causes acommand not founderror.echo hi). Forecho hia doubleeval eval ${...}works, but I don't know what would be the other case.