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.
| xargswhat is thatxargsdoing there?:legal in function names? I'd be surprised.