Module: Dotenv::Substitutions::Command

Defined in:
lib/dotenv/substitutions/command.rb

Constant Summary collapse

INTERPOLATED_SHELL_COMMAND =
/
  (?<backslash>\\)?
  \$
  (?<cmd>             # collect command content for eval
    \(                # require opening paren
    ([^()]|\g<cmd>)+  # allow any number of non-parens, or balanced parens (by nesting the <cmd> expression recursively)
    \)                # require closing paren
  )
/x

Class Method Summary collapse

Class Method Details

.call(value, env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dotenv/substitutions/command.rb', line 16

def call(value, env)
  # Process interpolated shell commands
  value.gsub(INTERPOLATED_SHELL_COMMAND) do |*|
    command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses

    if $~[:backslash]
      $~[0][1..-1]
    else
      `#{command}`.chomp
    end
  end
end