Module: Dotenv::Substitutions::Command

### Home Classes Methods

### In Files

- lib/dotenv/substitutions/command.rb

### Methods

- ::call

### Class/Module Index

Quicksearch

- Dotenv
- Dotenv::CLI
- Dotenv::Environment
- Dotenv::FormatError
- Dotenv::Parser
- Dotenv::Substitutions
- Dotenv::Substitutions::Command
- Dotenv::Substitutions::Variable

No matching classes.

# Dotenv::Substitutions::Command

Substitute shell commands in a value.

    SHA=$(git rev-parse HEAD)

### Constants

INTERPOLATED_SHELL_COMMAND

### Public Class Methods

call(value, _env) click to toggle source

    # File lib/dotenv/substitutions/command.rb, line 23
    def call(value, _env)
      # Process interpolated shell commands
      value.gsub(INTERPOLATED_SHELL_COMMAND) do |*|
        # Eliminate opening and closing parentheses
        command = $LAST_MATCH_INFO[:cmd][1..-2]

        if $LAST_MATCH_INFO[:backslash]
          # Command is escaped, don't replace it.
          $LAST_MATCH_INFO[0][1..-1]
        else
          # Execute the command and return the value
          `#{command}`.chomp
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.