I’m sorry, but I almost spit my drink out at how unreadable the very first example is.

  trim_string() {
      # Usage: trim_string "   example   string    "
      : "${1#"${1%%[![:space:]]*}"}"
      : "${_%"${_##*[![:space:]]}"}"
      printf '%s\n' "$_"
  }

I mean, does it really need to be readable? I kind of took this site to be “here’s some snippets of code that you can use in your scripts to use instead of calling an external process.” Which means to me, I’m going to copy/paste this function into my script, call the function (since it’s structured as one), and never think about it again.

“Learn how to write routines like this and make them readable” seems like it’s not the point of this “Bible”.

I’m not against readable code by any means (maybe there’s even a cleaner way to write this) but it seemed inconsequential in my opinion.

Ideally, the function is POSIX-compatible, so it runs on the widest number of platforms.

Why do we want to adhere to POSIX?

  $ man bash | grep slow
         It's too big and too slow.

  $ rpm -qi dash | tail -3
  DASH is a POSIX-compliant implementation of /bin/sh that aims to be as small as
  possible. It does this without sacrificing speed where possible. In fact, it is
  significantly faster than bash (the GNU Bourne-Again SHell) for most tasks.
So let's find out how this function works in dash.

  $ ./testtrim
  ./testtrim

  $ sed -i 's/dash/bash/' testtrim          
  $ ./testtrim                              
  foo bar
I think I will pass.
There is https://github.com/dylanaraps/pure-sh-bible, including a trim function.