Skip to content

Instantly share code, notes, and snippets.

@taufiqpsumarna
Last active September 23, 2024 09:31
Show Gist options
  • Save taufiqpsumarna/f9658499cf89a88393bd469707893889 to your computer and use it in GitHub Desktop.
Save taufiqpsumarna/f9658499cf89a88393bd469707893889 to your computer and use it in GitHub Desktop.
Bash script for checking .env file and load it into current shell
#!/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