Last active
May 20, 2016 11:38
-
-
Save DominicImhof/7d457b0a023e068b7d58104fe87ce355 to your computer and use it in GitHub Desktop.
set variable in a .env file
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
PLATFORM=$(uname) | |
KEY=$1 | |
VAL=$2 | |
# Use awk instead of grep, since grep is not able to handle multiline regex | |
if [ "$(awk "/^$KEY=.*$/" .env)" != "" ]; then | |
if [ "$PLATFORM" = "Darwin" ]; then | |
sed -i '' -E "s~$KEY=.*~$KEY=$VAL~g" .env | |
else | |
sed -i "s~$KEY=.*~$KEY=$VAL~g" .env | |
fi | |
else | |
echo "$KEY=$VAL" >> .env | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment