简体   繁体   中英

how to read from a json file and create a environment variable in cli?

I want to read the aws credentials file and create the aws keys environment variable dynamically by reading the file

I need this because I have aws credentials expiring on short terms

so every time i need to created a new set of keys and then set it to env variables

what I want is to parse the credential file and set it directly to env variable

I have the credentials in a json file

I am using 'jq' to parse the json by command

cat credentials.json | jq .Credentials.AccesskeyId

cat credentials.json | jq .Credentials.SecretKey

now how can I use the output in setting the value in something like

export AWS_ACCESS_KEY = output of (cat credentials.json | jq .Credentials.AccesskeyId)

The syntax for what you want to achieve is the following:

export AWS_ACCESS_KEY_ID=$(cat credentials.json | jq .Credentials.AccesskeyId)
export AWS_SECRET_ACCESS_KEY=$(cat credentials.json | jq .Credentials.SecretKey)

I tested this in both bash and zsh shells.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM