You also have to escape the double-quotes inside the awk command.
Code:
watch -n 1 "top -b -n 1 | awk '{if (\$8 == \"D\") {print; count++} } END {print count}'"
Basically, single-quotes escape everything, while double-quotes escape everything inside them except for
$,
`, and
\, and of course another
", which ends the sequence. This means that inside double-quotes you can use \ to escape anything that could be a problem, including other double-quotes. But inside single-quotes you can't use anything, not even the escape character.
Note also that double-quotes lose their special meaning inside single quotes, and vice-versa.
So in this case, you have to use double-quotes around the phrase as a whole, which allows you to use escapes, then you need to escape any [
$`\"] characters that are intended to be fed to the commands inside. In this case, you need to protect the
$ and
" inside the awk expression, because the single-quotes surrounding them have lost their special bash meaning.