watch ps aux | grep foo is not working: bash: syntax error near unexpected token `}'
How can I fix this or is there even a better way?
watch ps aux | grep foo is not working: bash: syntax error near unexpected token `}'
How can I fix this or is there even a better way?
The problem is that you are watching the wrong thing
watch ps aux | grep fooimplies that you want to grep foo in the output of watch - which unfortunately is silent by itself. It is indeed running ps aux every 2 seconds, but not printing anything on stdout.
However , the following
watch 'ps aux | grep foo'implies you want to watch if anything matching foo is printed by ps aux . And that is what you want to do.
Hence you would want to go with Option 2