$ echo -n "$a" | md5sum
$ echo -n "$a" > foo
$ cat foo | md5sum
$ [ "$(cat foo)" == "$a" ] || echo false
$( ) trims trailing newlines. From the bash reference manual (emphasis added):
Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.
You can see this directly by printing the value of
$ echo "'$a'" 'a ' $ echo "'$(cat foo)'" 'a'
...note that with
$( ), the closing single-quote winds up on the same line as the "a", meaning there's no newline after the "a". Also,
$ [ "$(cat foo)" = "a" ] && echo true || echo false true
Note that that's comparing against the string "a", which does not contain a newline; not the variable
$a, which does contain a newline.