Created
February 27, 2015 07:44
-
-
Save akm/c6d06c1d81d8a7189c5e to your computer and use it in GitHub Desktop.
single quote escape for bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sq_escape(str) | |
str.split(/\'/).map{|s| "'#{s}'"}.join("\\'") | |
end | |
sq_escape {"breakfast"=>"Bill's"}.to_json | |
#=> "'{\"breakfast\":\"Bill'\\''s\"}'" | |
puts sq_escape {"breakfast"=>"Bill's"}.to_json | |
#=> '{"breakfast":"Bill'\''s"}' | |
# # on bash | |
# $ echo '{"breakfast":"Bill'\''s"}' | |
# {"breakfast":"Bill's"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment