I'm trying to get watch to work correct with commands that contain quotes, and the watch man page isn't very detailed about how quotes work. To give a concrete example, how can I run the following command inside of watch:

ps -ef | awk -F' ' '{print $2}'

I've tried:

watch "ps -ef | awk -F' ' '{print $2}'"

and

watch 'ps -ef | awk -F\' \' \'{print $2}\''

but neither of these works correctly.

link|improve this question

feedback

2 Answers

up vote 2 down vote accepted

I guess you have to escape the $ sign:

watch "ps -ef | awk -F' ' '{print \$2}'"

otherwise it would be interpreted by the shell which would result in an empty string ("") - i.e. awk would print the whole line.

link|improve this answer
feedback

You could always put your command in a shell script, then "watch" the script.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.