Following up on the top answer to this question, I thought I could:
1) Define a command:
cmd='for x in $(my_command | grep keyword | cut -d" " -f1); do command2 "arguments" $x; done'
2) Run it on a loop as follows
while true; do "$cmd"; sleep 1; done
However, the above doesn't work, and I get the following
zsh: command not found for x in $(......
zsh: command not found for x in $(......
zsh: command not found for x in $(......
...
Any thoughts why?
Clarification:
If I run for x in $(my_command | grep keyword | cut -d" " -f1); do command2 "arguments" $x; done'
it works perfectly.
Addendum:
I have noticed that if I use eval
, it works, i.e.:
while true; do eval "$cmd"; sleep 1; done
runs the command cmd
every second
zsh
have the same for construct? – Kevin Oct 26 '11 at 21:55eval "$cmd"
or just running the contents ofcmd
work. – Amelio Vazquez-Reina Oct 26 '11 at 21:57