I am trying to change "/foo/bar/dir"to "\/foo\/bar\/dir"ruby gsub command.
I am testing it in irb, the result
x = "/foo/bar/dir"
x.gsub("/","\/")
=> "/foo/bar/dir"
x.gsub("/","\\/")
=> "\\/foo\\/bar\\/dir"
Is it possible to replace "/" with "/" on gsub?
Source of problems:
I am trying to execute a "command line", and "real_path" is my variable
real_path = "/home/me/www/idata"
path = real_path.gsub("/","\\/")
=> \\/home\\/me\\/www\\/idata
run "sed 's/SHARE_PATH/#{path}/g' #{path}/config/sphinx.yml > #{path}/config/sphinx.tmp.yml"
run command result
"sh -c 'sed '\''s/SHARE_PATH/\\/home\\/me\\/www\\/idata\\/shared/g .... "
I need only one backslash, for example
"sh -c 'sed '\''s/SHARE_PATH/\/home\/me\/www\/idata\/shared/g .... "
"run" is a command from Capistrano
my decision
use a single quote instead of a double quote like this
path = real_path.gsub("/",'\/')
source
share