Normalize Whitespace

Replace multiple consecutive whitespace characters with a single space and trim edges.

Code

General
echo "$s" | tr -s ' ' | xargs

Parameters

String with irregular whitespace

Server

More Bash Snippets