Skip to content

Instantly share code, notes, and snippets.

@mattak
Last active July 20, 2023 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattak/5d532e5d78d311a3c75ac56f948bbebd to your computer and use it in GitHub Desktop.
Save mattak/5d532e5d78d311a3c75ac56f948bbebd to your computer and use it in GitHub Desktop.
import-env
#!/bin/bash
for kv in $(< $1)
do
if [[ "$kv" = ^\s*$ ]] || [[ "$kv" =~ ^# ]]; then
continue
fi
export $kv
done
@mattak
Copy link
Author

mattak commented Jul 20, 2023

Install

chmod +x import-env
mv import-env /any/where/bin/import-env

Usage

.env

ENV_VALUE=1

your_script.bash

#!/bin/bash

. import-env .env

# output: 1
echo $ENV_VALUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment