สภาพแวดล้อมการส่งออกตัวแปรจากสคริปต์ทุบตีพร้อมอาร์กิวเมนต์

source ./script.sh dev
#!/bin/bash
# Check 1 argument is passed with the script
if [ $# -ne 1 ]
then
        echo "Usage : $0 AWS account: e.g. $0 dev"
        exit 0
fi

# convert the input to uppercase
aws_env=$( tr '[:lower:]' '[:upper:]' <<<"$1" )


if ! [[ "$aws_env" =~ ^(DEV|UAT|TRN|PROD)$ ]]; then 
    # check that correct account is provided
    echo "Enter correct AWS account: dev or uat or trn or prod"
    exit 0

else
    # export environment variables
    file="/home/xyz/.aws/key_${aws_env}"
    IFS=$'\n' read -d '' -r -a lines < $file
    export AWS_ACCESS_KEY_ID=${lines[0]}
    export AWS_SECRET_ACCESS_KEY=${lines[1]}
    export AWS_DEFAULT_REGION=ap-southeast-2
    echo "AWS access keys and secret has been exported as environment variables for $aws_env account"
fi