My bash script uses a perl command to replace a variable within a file, with the contents of another file. Pretty standard I thought, yet I am really struggling here.
#/bin/bash
display_usage() {
echo -e "\nUsage: This script must be run with an environment parameter (file in directory env/)."
echo -e "Example: ./configureEnv <env parameter>\n"
}
# If no env argument supplied, display usage.
if [ $# -eq 0 ]; then
display_usage
exit 1
fi
# Replace the placeholder of FIREBASE_ENV in index.html with the Firebase env settings.
perl -pi -e 's/%FIREBASE_ENV%/`cat testEnvConfig`/g;' index.html
if [ $? -eq 0 ]; then
echo "Updated Firebase settings based on environment file: $1"
exit 0
else
echo "[Error] Environment settings configuration failed. Please check parameters are correct."
exit 1
fi
As you can see, the key line is:
perl -pi -e 's/%FIREBASE_ENV%/`cat testEnvConfig`/g;' index.html
It should replace the placeholder string of %FIREBASE_ENV% with the contents of the file, but instead it replaces replaces %FIREBASE_ENV% with `cat testEnvConfig`.