test: use a match for stderr

The stderr test on linux can return either

<<"nonexistent: not found\n">>

or:

<<"sh: ">>

Probably the shell is using 2 writes to produce the error message, which
may or may not be buffered into one read. Use a pattern match to avoid
the test failing.

Add a separate test for freebsd (untested).