Ruby 2.2.0 リファレンスマニュアル > ライブラリ一覧 > shellwordsライブラリ > Shellwordsモジュール > shellescape

module function Shellwords.#shellescape

shellescape(str) -> String[permalink][rdoc]

文字列を Bourne シェルのコマンドライン中で安全に使えるようにエスケープします。

[PARAM] str:
エスケープの対象となる文字列を指定します。
[RETURN]
エスケープされた文字列を返します。

例:

require 'shellwords'

pattern = 'Jan 15'
puts "grep #{Shellwords.shellescape(pattern)} file"
# => grep Jan\ 15 file