Created
December 25, 2022 13:41
-
-
Save osadan/5248f8f115ca4ef44e9904b8656fc323 to your computer and use it in GitHub Desktop.
sed code to switch .env attributes
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
#!/bin/bash | |
FILE_PATH=<env file path> | |
echo $1 | |
ESCAPED_REPLACE=$(printf '%s\n' "$2" | sed -e 's/[\/&]/\\&/g') | |
echo $ESCAPED_REPLACE | |
sed -i \ | |
-r "s/^($1=).*/\1$ESCAPED_REPLACE/" $FILE_PATH | |
grep -q -e "$1=$2" $FILE_PATH || echo $1=$2 >> $FILE_PATH | |
cat $FILE_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment