Ruby escape ARGV argument or string as argument to shell command

后端 未结 3 548
情话喂你
情话喂你 2021-02-05 04:02

Ok this is driving me crazy:

`ls #{\"/media/music/Miles Davis\"}`

fails because of the space between \"Miles\" and \"Davis\"

Say I writ

3条回答
  •  -上瘾入骨i
    2021-02-05 04:39

    Use require 'shellwords' and Shellwords.escape, which will fix this sort of stuff for you:

    http://apidock.com/ruby/Shellwords/shellescape

提交回复
热议问题