Skip to content

Instantly share code, notes, and snippets.

@binlab
Forked from wyllie/parse_ini.sh
Created August 18, 2021 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binlab/2657166349f294ad31f8a7aa5a3f9d51 to your computer and use it in GitHub Desktop.
Save binlab/2657166349f294ad31f8a7aa5a3f9d51 to your computer and use it in GitHub Desktop.
Parse aws credentials file in bash
#!/usr/bin/env bash
INI_FILE=~/.aws/credentials
while IFS=' = ' read key value
do
if [[ $key == \[*] ]]; then
section=$key
elif [[ $value ]] && [[ $section == '[default]' ]]; then
if [[ $key == 'aws_access_key_id' ]]; then
AWS_ACCESS_KEY_ID=$value
elif [[ $key == 'aws_secret_access_key' ]]; then
AWS_SECRET_ACCESS_KEY=$value
fi
fi
done < $INI_FILE
echo $AWS_ACCESS_KEY_ID
echo $AWS_SECRET_ACCESS_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment