I'd like to use bash to replace multiple adjacent spaces in a string by a single space. Example:
Original string:
"too many spaces."
Transformed string:
"too many spaces."
I've tried things like "${str//*( )/.}"
or awk '{gsub(/[:blank:]/," ")}1'
but I can't get it right.
Note: I was able to make it work with <CMD_THAT_GENERATES_THE_INPUT_STRINGH> | perl -lpe's/\s+/ /g'
but I had to use perl to do the job. I'd like to use some bash internal syntax instead of calling an external program, if that is possible.