Last active
April 12, 2025 23:52
-
-
Save iTrooz/4caeaf2f26c5d4a1ee06f33917cd6fa7 to your computer and use it in GitHub Desktop.
Execute a command with environment set from .env
This file contains hidden or 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/sh | |
# Source: https://gist.github.com/iTrooz/4caeaf2f26c5d4a1ee06f33917cd6fa7 | |
# Syntax: loadenv <command> [args] | |
if [ -f .env ] | |
then | |
while IFS= read -r line || [ -n "$line" ]; do | |
var="${line%%#*}" | |
[[ -n "$var" ]] && eval "export $var" # Eval is needed for quoted values | |
done < .env | |
else | |
>&2 echo "Warning: no .env file found" | |
fi | |
$@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment