I need some help with my script.
I have environmental variables like these:
SECRET_OF_AN_APP_dev=123
SECRET_OF_AN_APP_test=456
SECRET_OF_AN_APP_prod=789
I want to have a script that will change SECRET_OF_AN_APP_dev=123 to SECRET_OF_AN_APP=123 and export it into env in first iteration, then SECRET_OF_AN_APP_test=456 change to SECRET_OF_AN_APP=456 in second iteration etc.
#!/bin/bash
APP_SECRET=SECRET_OF_AN_APP
ENVIRONMENT_NAME=dev
LIST_OF_ENVIRONMENTS=[dev, prod, test...]
for i in $LIST_OF_ENVIRONMENTS
do
APP_SECRET=$(env | grep APP_SECRET_$i | sed 's/APP_SECRET_'"$i"'=//g' ) >> var.bash
. ./var.bash
./some_script_where_$APP_SECRET_is_required.sh
done
I think my script is working in something like a subshell because when I do: echo $SECRET_OF_AN_APP
, it's blank.
I need to have it set because other scripts which are executing in this loop need those variables.
I tried with export
, with ./var.bash
, with set -o allexport
, etc.
Nothing is working.
I need to have "echo $SECRET_OF_AN_APP" in my shell, not only script. It's working in script. but it's not set in my environmental variables.
SECRET_OF_AN_APP
andAPP_SECRET
. Please [edit] your question and make sure all parts are consistent. Copy&paste the exact code you run on your system. Use https://www.shellcheck.net/. Apart from all other problems and inconsistencies, you have toexport
the variable to make it available for the called script (unless you instructed the shell to export all variables). – Bodo Apr 07 '22 at 12:21