Strings In Depth17 / 17
Up next

Trim whitespace

#!/usr/bin/env bash
s="   padded   "
# strip leading spaces, then trailing spaces
s="${s#"${s%%[![:space:]]*}"}"
s="${s%"${s##*[![:space:]]}"}"
echo "[$s]"
What you're solving

extglob strips leading and trailing spaces