0

I am trying to configure the AWS CLI using a bash script. I have the below in my script and it will not set the values. When I echo out the variables names it just shows a blank line.

script code

export AWS_ACCESS_KEY_ID=<key>

export AWS_SECRET_ACCESS_KEY=<secret_key>

export AWS_DEFAULT_REGION=<region>

marked as duplicate by Kusalananda linux Aug 15 '18 at 13:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • how are you trying to print the variables ... contents (not names)? After/outside the script, or within the script? – Jeff Schaller Aug 15 '18 at 13:15
  • You have to source the script instead of running it. – Rui F Ribeiro Aug 15 '18 at 13:16
  • I am trying to echo out the variables because they are not working. I these values are to be used by the AWS cli program. I am testing the echo outside the script once it has ran. – Josh Kirby Aug 15 '18 at 13:17
  • @RuiFRibeiro What do you mean? – Josh Kirby Aug 15 '18 at 13:17
  • 1
    @JoshKirby, please edit your question to include a complete example of a script that exhibits the issue, along with a sample of how you run the script. sh -c 'export ID=foo; echo "$ID"' should work with whatever sh you have, so there's not enough information here to tell what the issue is. – ilkkachu Aug 15 '18 at 13:21
0

Superuser: what-is-the-difference-between-executing-a-bash-script-vs-sourcing-it

Short answer: sourcing will run the commands in the current shell process. executing will run the commands in a new shell process.

More info in the original question/answer

The below example shows the difference between running the script and sourceing it:

$ cat a.sh
export AWS_ACCESS_KEY_ID=key
export AWS_SECRET_ACCESS_KEY=secret_key
export AWS_DEFAULT_REGION=region
$ ./a.sh 
$ echo $AWS_ACCESS_KEY_ID

$ source a.sh 
$ echo $AWS_ACCESS_KEY_ID
key
$ 

Not the answer you're looking for? Browse other questions tagged or ask your own question.