Skip to content

Instantly share code, notes, and snippets.

@osadan
Created December 25, 2022 13:41
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 osadan/5248f8f115ca4ef44e9904b8656fc323 to your computer and use it in GitHub Desktop.
Save osadan/5248f8f115ca4ef44e9904b8656fc323 to your computer and use it in GitHub Desktop.
sed code to switch .env attributes
#!/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