Skip to content

Instantly share code, notes, and snippets.

@rafaelbeckel
Created March 17, 2018 20:11
Show Gist options
  • Save rafaelbeckel/39adee6f92aa1a07d686855ac7b322e9 to your computer and use it in GitHub Desktop.
Save rafaelbeckel/39adee6f92aa1a07d686855ac7b322e9 to your computer and use it in GitHub Desktop.
Bash Script - Read variable from .env file
#!/bin/bash
read_var() {
VAR=$(grep $1 $2 | xargs)
IFS="=" read -ra VAR <<< "$VAR"
echo ${VAR[1]}
}
MY_VAR=$(read_var MY_VAR .env)
@TheGitPanda
Copy link

It just works. Thank you!

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