« Back to Index

Shell: Write to a variable multiple times before writing to disk

View original Gist on GitHub

Tags: #bash #shell #performance

example.bash

function bar {
  example=$(echo "$example" | rg $1 \
    --case-sensitive \
    --type go \
    --type md \
    --color never \
    --no-line-number \
    --passthru \
    --replace $2)
}

function foo {
  example=$(<fastly-go/go.mod)
  bar "github" "GITHUB"
  bar "google" "GOOGLE"
  echo "$example" > final.txt
  cat final.txt
  rm final.txt
}

foo