Basically I have the next code:
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
export AWS_ACCESS_KEY_ID=$(echo $OUTPUT_ROLE | jq -r '.Credentials''.AccessKeyId');\
export AWS_SECRET_ACCESS_KEY=$(echo $OUTPUT_ROLE | jq -r '.Credentials''.SecretAccessKey');\
export AWS_SESSION_TOKEN=$(echo $OUTPUT_ROLE | jq -r '.Credentials''.SessionToken');
echo "AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID"
echo "AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY"
echo "AWS_SESSION_TOKEN: $AWS_SESSION_TOKEN"
in my bash script it starts with: #!/usr/bin/env sh
in the console after the script ends I can see the respective env vars with the correct values, such as:
AWS_ACCESS_KEY_ID: <value>
AWS_SECRET_ACCESS_KEY: <value>
AWS_SESSION_TOKEN: <value>
But if I do echo $AWS_ACCESS_KEY_ID for example direct in the console, or any other var y got an empty value, it seems like the variables are not set correctly in the current bash session and I am not able to execute new commands related with these vars.
Also doing other tests it seems like unset is not working properly neither, any guidance, I'm not able to figure out what is going on.
I am executing the script with ./script.sh also with source script.sh and bash script.sh with same results. I am using the git bash console for windows.
I did a short example such as:
var="Hello"
echo "start:$var"
# Delete the var
unset var
echo "final:$var"
var="new"
echo "new:$var"
the output is after execution ./example1.sh is:
start:Hello
final:
new:new
But if I do echo $var direct in the console, after the script execution I got empty using both formats #!/usr/bin/env bash and #!/usr/bin/env shh.
shis not bash. A sh script is not a bash script. If you want bash features, you need to use bash (#!/usr/bin/env bash), not sh (#!/usr/bin/env sh).echo "$OUTPUT_RULE", notecho $OUTPUT_RULE-- see I just assigned a variable, butecho $variableshows something else!source script.shis expected to set variables in the parent shell. Running./script.shorbash script.shruns the script inside a new interpreter, sets the variables there... and then throws away the variables (and the effects of operations likeunset) when that new interpreter exits at the end of the script.sourcenot working; since two of your three usage attempts are things that aren't expected to work in the first place, a transcript showing how you tested the one that is expected to work would be a good place to start. Consider usingset -xto enable trace logging, and possibly setting a PS4 that logs the PID of the current process so it can be determined when process boundaries are crossed.