Escape special characters used in most unix shells to use it, eg. with system().
This differs from Ruby’s #escape in that it does not escape shell variables, e.g. $0.
# File lib/standard/facets/shellwords.rb, line 12 def alt_escape(cmdline) cmdline.gsub(/([\\\t\| &`<>)('"])/) { |s| '\' << s } end
Escape special character used in DOS-based shells.
TODO: How to integrate with rest of system?
Use platform condition?
Use separate dos_xxx methods?
Put in separate PowerShellwords module?
CREDIT: Lavir the Whiolet
# File lib/standard/facets/shellwords.rb, line 30 def dos_escape(cmdline) '"' + cmdline.gsub(/\\(?=\\*\")/, "\\\\\\").gsub(/\"/, "\\\"").gsub(/\\$/, "\\\\\\").gsub("%", "%%") + '"' end
# File lib/standard/facets/shellwords.rb, line 17 def escape(cmdline) cmdline.gsub(/([\\\t\| &`<>)('"])/) { |s| '\' << s } end