LoginSignup
5
5

More than 5 years have passed since last update.

シングルクォートを含むテキストをshellに食わせるには

Posted at

やりたいこと

stringは改行やシングルクォート、マルチバイト文字を含むフリーテキスト。

`echo #{string} | somecommand`

結論

string.gsub(/'/, "'\\\\''") 

理屈

Rubyによるシングルクォートのエスケープの罠

shellでのシングルクォートのエスケープの罠

5
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5