Given a variable or stdout of a command in bash containing multiple lines, how can I trim leading and trailing whitespace characters (including line breaks)?
Note: I want to use this in trimmed string comparison, i.e.
[[ "$(command1-that-produces-multiline-string)" == "$(command2-that-produces-multiline-string)" ]]
As one of the commands produces trailing newline(s) while the other does not, the comparison fails.