Bash Trim

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Internal

Overview

Trim Spaces

With variable manipulation:

trailing_space_removed=${var_name%%[[:space:]]}
leading_space_removed=${var_name##[[:space:]]}

With sed:

sed -e 's/^ *//' -e 's/ *$//'

Trim New Line

With tr:

tr -d