News for hackers. Stuff that matters.
Re:Pure Bash Bible by jolmg on Thursday September 19, 2019 @01:24PM (#21018420)
> echo "$FOO" | sed -e ' s/^[[:space:]]//g; s/[[:space:]]$//g '

Your example fails when $FOO is "-n", for instance. Also the g modifiers are redundant in your example since there's only one beginning of line per line and one end of line per line.

I would instead write this:

  sed -r 's/^\s+|\s+$//g' <<< "$FOO"
EDIT: I think I see now what you probably thought would happen by using g, but no it wouldn't remove multiple spaces. So, you example also fails when $FOO is " x" (using 2 or more spaces at the ends).
Re:Pure Bash Bible by jwilk on Friday September 20, 2019 @03:13PM (#21030190)
Beware that -r is a GNU-specific option.