Module: Dory::Bash
- Defined in:
- lib/dory/shell.rb
Class Method Summary collapse
- .escape_double_quotes(str) ⇒ Object
- .escape_single_quotes(str) ⇒ Object
- .run_command(command) ⇒ Object
Class Method Details
.escape_double_quotes(str) ⇒ Object
21 22 23 |
# File 'lib/dory/shell.rb', line 21 def self.escape_double_quotes(str) str.gsub('"', '\\"') end |
.escape_single_quotes(str) ⇒ Object
16 17 18 19 |
# File 'lib/dory/shell.rb', line 16 def self.escape_single_quotes(str) # Using this technique here: https://stackoverflow.com/a/1315213/2062384 str.gsub("'", "'\\\\''") end |
.run_command(command) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dory/shell.rb', line 25 def self.run_command(command) stdout = `bash -c "#{self.escape_double_quotes(command)}"` OpenStruct.new({ success?: $?.exitstatus == 0, exitstatus: $?.exitstatus, stdout: stdout }) end |