Created
October 4, 2019 04:48
-
-
Save abdennour/d57a25472f5d924e0cba9f011db18e2f to your computer and use it in GitHub Desktop.
Dynamically replace environment variable names by its values inside file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM perl:5-slim | |
WORKDIR /data | |
COPY myfile.txt . | |
RUN perl -pe 's/\$([_A-Z]+)/$ENV{$1}/g' < myfile.txt > /tmp/myfile.txt | |
RUN perl -pe 's/\$(\{)?([a-zA-Z_]\w*)(?(1)\})/$ENV{$2}/g' < /tmp/myfile.txt > myfile.txt | |
# Only substitute variable that are defined perl -pe 's{\$(\{)?(\w+)(?(1)\})}{$ENV{$2} // $&}ge' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker build -t substituter:0.1 . | |
docker run --rm -v $(pwd):/data substituter:0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello ${NAME} | |
Thank you ${NAME} for sending ${THING}. | |
I like this $THING | |
Thank you again $NAME | |
Best |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment