def recursively_find_and_replace_command_substitutions(input)
      input = input.dup
      Parser.each_command_substitution_for(input) do |substitution_result, start_position, end_position|
        debug_log "found command substitution at position=#{(start_position..end_position)} #{substitution_result.inspect}"
        result = recursively_find_and_replace_command_substitutions(substitution_result.str)
        position = substitution_result.position
        ast = Parser.parse(result)
        with_standard_streams do |stdin, stdout, stderr|
          r,w = IO.pipe
          @stdout = w
          ast.accept(self)

          output = r.read.chomp

          # Treat consecutive newlines in output as a single space
          output = output.gsub(/\n+/, ' ')

          # Double quote the output and escape any double quotes already
          # existing
          output = %|"#{output.gsub(/"/, '\\"')}"|

          # Put thd output back into the original input
          debug_log "replacing command substitution at position=#{(position.min...position.max)} with #{output.inspect}"
          input[position.min...position.max] = output
        end
      end
      input
    end
def recursively_find_and_replace_command_substitutions(input)
      input = input.dup
      Parser.each_command_substitution_for(input) do |substitution_result, start_position, end_position|
        debug_log "found command substitution at position=#{(start_position..end_position)} #{substitution_result.inspect}"
        result = recursively_find_and_replace_command_substitutions(substitution_result.str)
        position = substitution_result.position
        ast = Parser.parse(result)
        with_standard_streams do |stdin, stdout, stderr|
          r,w = IO.pipe
          @stdout = w
          ast.accept(self)

          output = r.read.chomp

          # Treat consecutive newlines in output as a single space
          output = output.gsub(/\n+/, ' ')

          # Double quote the output and escape any double quotes already
          # existing
          output = %|"#{output.gsub(/"/, '\\"')}"|

          # Put thd output back into the original input
          debug_log "replacing command substitution at position=#{(position.min...position.max)} with #{output.inspect}"
          input[position.min...position.max] = output
        end
      end
      input
    end
+recursively_find_and_replace_command_substitutions+ is responsible for recursively
 finding and expanding command substitutions, in a depth first manner.