#!/usr/bin/env bash

SEP="########################################################################"

export NEW_VAR="17171"

mkdir cache
# Create a file from a multiline string
cat > cache/temp.txt <<- HEREDOC
Hello! This is a multiline files.
This is my path: \${PATH}
\${NEW_VAR}
+----
#....
?////

HEREDOC
echo "temp.txt content:"
cat cache/temp.txt

printf "\n%s\n" "$SEP"

# Replace env vars in template file and write to new file
envsubst < cache/temp.txt > cache/output.txt
echo "output.txt content:"
cat cache/output.txt

printf "\n%s\n" "$SEP"

# Replace env vars using sed
echo "output from sed:"
sed "s|\${PATH}|${PATH}|g" < cache/temp.txt
rm -rf cache

printf "\n%s\n" "$SEP"
