bash: Make `trim` a function

Things complained when it was invoked in a non-interactive shell because
it was not available.