Is logic based on stdout manipulation considered "crude" in professional bash scripting?

"stdout manipulation"

Usually called output parsing. It does happen a quite lot and yes it is problematic for the reason you mention.

In this particular situation I would recommend pgrep command, which is part of procps package (on Ubuntu). Mmm.. not sure about portability here though.

number_of_processes=$(pgrep -c ...)

Yep ... -c flag of pgrep means something different on BSD ... https://www.freebsd.org/cgi/man.cgi?query=pgrep

Side notes

  1. grep ... | wc -l can be grep -c , at least on some platforms.
  2. Newer non POSIX shells are working with structured data exactly due to the output parsing (and related) issues. Example: https://github.com/nushell/nushell . Let's put PowerShell aside for a moment because while the word "Power" is appropriate, the language itself is pretty horrible.
/r/bash Thread