The problem seems related to the backslash losing the meaning you intend when interpreted by the shell. There's probably some incantation of quoting that would eliminate the issue, but for me it's sometimes just easier to dump the output of a construct into Perl for further processing.
If you can accept a solution that invokes Perl on your system, this works:
echo foo | md5sum | perl -nE 'say "ok" if m/^\bd3b07384d113edec49eaa6238ad5ff00\b/'
If you're stuck with a Perl that predates v5.10, then this:
echo foo | md5sum | perl -lne 'print "ok" if m/^\bd3b07384d113edec49eaa6238ad5ff00\b/'
The solution is fairly self-explanatory if you read through perlrun, which explains what the various command line switches do. We're using -n
to cause Perl to process some input, -E
to tell Perl to evaluate some code using modern (5.10+) features (say
), and the rest just reads as you would expect.
For older Perl versions (pre-5.10), say
wasn't available, so the command line switches change to -l
, -n
, and -e
: The first strips newlines from input (not useful), and adds them to output (useful, because print
doesn't do that, where the newer say
does). And the -e
to evaluate some code using pre-5.10 semantics.