Last active
September 23, 2024 09:31
-
-
Save taufiqpsumarna/f9658499cf89a88393bd469707893889 to your computer and use it in GitHub Desktop.
Bash script for checking .env file and load it into current shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if $ENV_FILE variable is set | |
if [ -z .env ]; then | |
echo "Error: ENV_FILE variable is not set. Please specify the path to the .env file." | |
exit 1 | |
fi | |
# Check if the .env file exists | |
if [ ! -f .env ]; then | |
echo "Error: The specified .env file .env does not exist." | |
exit 1 | |
fi | |
# Load environment variables from .env file | |
echo "Loading environment variables from .env file" | |
source .env | |
#Export .env artifact to current stage | |
export $(cat .env | grep -v '#' | xargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment