Before this PR:
Failed to replace value in .env file with sed on Mac.
(dify-api-py3.10) bw@bwdeMacBook-Pro-2 api % sed -i 's/SECRET_KEY=.*/SECRET_KEY=QDyaHv8M5kuJ6XpNxEHXZ0OD6B029cKNrOt+VPxky70ixTGAwRBNtULn/' .env
sed: 1: ".env": invalid command code .
With this PR:
To solve this problem,
Possible approach 1 with sed :
On Mac:
sed -i '' "s/^SECRET_KEY=.*/SECRET_KEY=$(printf '%s' "$(openssl rand -base64 42)" | sed 's/[\/&]/\\&/g')/" .env
On Linux:
sed -i "s/^SECRET_KEY=.*/SECRET_KEY=$(printf '%s' "$(openssl rand -base64 42)" | sed 's/[\/&]/\\&/g')/" .env
Possible approach 2 with awk (recommended and used in this PR as it has clear syntax without escaping characters like sed):
Before this PR: Failed to replace value in
.env
file withsed
on Mac.(dify-api-py3.10) bw@bwdeMacBook-Pro-2 api % sed -i 's/SECRET_KEY=.*/SECRET_KEY=QDyaHv8M5kuJ6XpNxEHXZ0OD6B029cKNrOt+VPxky70ixTGAwRBNtULn/' .env sed: 1: ".env": invalid command code .
With this PR:
To solve this problem,
Possible approach 1 with
sed
:Possible approach 2 with
awk
(recommended and used in this PR as it has clear syntax without escaping characters likesed
):