#!/bin/bash

SEARCH="$1"
REPLACE="$2"

for file in *.md; do
  SEARCH="$SEARCH" REPLACE="$REPLACE" perl -i -pe '
    BEGIN {
      $search = quotemeta($ENV{"SEARCH"});
      $replace = $ENV{"REPLACE"};
      $replace =~ s/\\/\\\\/g;  # escape backslashes in replacement
      $replace =~ s/\$/\\\$/g;  # escape $ in replacement
    }
    s/$search/$replace/g;
  ' "$file"
done

echo "Literal replacement complete."