Reputation: 2159
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.
Upvotes: 0
Views: 29