Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In a POSIX shell, I would do it like this:

  trim_string () (
  x=${1%[:space:]}
  return ${x#[:space:]}
  )
Note the use of a subshell ( instead of command grouping { because POSIX shells do not have local function variables.

At least, I think that would work.

On Windows, forking is expensive, so I wouldn't do it this way.



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: