I have a bash function that retrieves environment variables from a .env
file.
In my .env
file I have the following variables
USER=luis
IMAGE_NAME=application
IMAGE_VERSION=latest
IMAGE_TAG=${USER}/${IMAGE_NAME}:${IMAGE_VERSION}
In my bash script I have my env function
function dotenv::get() {
variable=$(grep ^"${1}"= "$(pwd)/.env" | xargs)
IFS="=" read -ra variable <<< "${variable}"
echo "${variable[1]}"
}
When I execute dotenv::get IMAGE_TAG
.
Expected result: luis/application:latest
Current result: ${USER}/${IMAGE_NAME}:${IMAGE_VERSION}
I'm aware my function is incomplete, however I'm not sure what are the next steps to achieve my objective.
question from:
https://stackoverflow.com/questions/65892044/bash-parse-environment-variables-in-bash-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…