2 Answers
2

By putting quotes around $cmd, you're asking the shell to run a command named exactly that. There is not command named "for x in $(..."; in fact on my system, there isn't even a command named "for" - it's a shell keyword. To run the contents of $cmd, you'll have to use eval.

Thanks @Shawn. Hhmm, but why does the above syntax work for watch then? (see the link to a related question at the beginning of the OP)
–
Amelio Vazquez-ReinaOct 26 '11 at 22:05

Nevermind, I think that @Guilles explained that in the watch example "$cmd" is passsed as an argument to bash, which I guess explains why it does not need eval
–
Amelio Vazquez-ReinaOct 26 '11 at 22:10

1

It is because the shell is expecting a string, which it interprets line-by-line; just as it would when running a script from a file.
–
Shawn J. GoffOct 26 '11 at 22:14