Shellwords.shellescape implementation for Ruby 1.8

bash, escaping, ruby, sh, shell

Solution

I wound up going with the Escape gem, which has the additional feature of using quotes by default, and only backslash-escaping when necessary.

Problem

While the build of 1.8.7 I have seems to have a backported version of `Shellwords::shellescape`, I know that method is a 1.9 feature and definitely isn't supported in earlier versions of 1.8. Does anyone know where I can find, either in Gem form or just as a snippet, a robust standalone implementation of Bourne-shell command escaping for Ruby?

Original source