I try to modify "/foo/bar/dir"
-> "\/foo\/bar\/dir"
before execute it in command line.
I test by using gsub in irb the result is
x = "/foo/bar/dir"
x.gsub("/","\\\/")
=> "\\\/foo\\\/bar\\\/dir"
x.gsub("/","\/")
=> "/foo/bar/dir"
Is it possible to replace "/" with "\/" by gsub ?
Source of problems is
I try to execute "string in command line" and "real_path" is my variable
real_path = "/home/me/www/idata"
path = real_path.gsub("/","\\\/")
puts path
=> \/home\/me\/www\/idata
run "sed 's/SHARE_PATH/#{path}/g' #{path}/config/sphinx.yml > #{path}/config/sphinx.tmp.yml"
result from "run" command is
"sh -c 'sed '\\''s/SHARE_PATH/\\\/home\\\/me\\\/www\\\/idata\\\/shared/g .... "
I need is only one back slash like
"sh -c 'sed '\\''s/SHARE_PATH/\\/home\\/me\\/www\\/idata\\/shared/g .... "
"run" is command from Capistrano
my solution is
use single quote instead of double quote like this
path = real_path.gsub("/",'\/')