Is there a way to do this in one line?
$x =~ s/^\\s+//; $x =~ s/\\s+$//;
In other words, remove all leading and trailing whitespace from a stri
In zsh with PCRE mode active:
function trim() { local out="$*" [[ "$out" =~ '^\s*(.*\S)\s*$' ]] && out="$match[1]" || out='' print -nr -- "$out" }