Skip to main content
edited tags
Link
muru
  • 77.9k
  • 16
  • 212
  • 318
added 486 characters in body
Source Link
HappyFace
  • 1.7k
  • 14
  • 29

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]}".

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}
}

And I want loop fsayd to be substituted as two words. 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 "$#")

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]}".

added 48 characters in body
Source Link
HappyFace
  • 1.7k
  • 14
  • 29

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}
}

And I want loop fsayd to be substituted as two words. 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 "$#")

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}
}

And I want loop fsayd to be substituted as two words. 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, or that timer 0 ff hi 'man hi jk k' failed. (ff() echo "$#")

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}
}

And I want loop fsayd to be substituted as two words. 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 "$#")

edited body; edited title
Source Link
muru
  • 77.9k
  • 16
  • 212
  • 318
Loading
edited tags
Link
jesse_b
  • 41.6k
  • 14
  • 108
  • 162
Loading
Source Link
HappyFace
  • 1.7k
  • 14
  • 29
Loading