Skip to content

Commit

Permalink
Update sed command for compatibility with MacOS
Browse files Browse the repository at this point in the history
Adapted the sed command in the prepare-dotenv.sh script to ensure compatibility with both MacOS and Linux. Previously, the script only worked on Linux systems, but now it accounts for differences in the sed command on Unix-based systems.
  • Loading branch information
jorgecuesta committed Jul 26, 2024
1 parent 49d11b4 commit 5419283
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions scripts/prepare-dotenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ else

for environment in $environments
do
# Create a copy of .env.sample for each environment
cp .env.sample .env.$environment
# Create a copy of .env.sample for each environment
cp .env.sample .env.$environment

# Replace ENV= with ENV=<environment> in each file
sed -i "s/^ENV=.*$/ENV=$environment/g" .env.$environment
# Replace ENV= with ENV=<environment> in each file
# The command differs depending on the Unix-based system (Linux/BSD) or Mac, due to differences in the sed command
# - On GNU sed (default on Linux), no space is used between -i and '' (or ""): sed -i'' 's/foo/bar/g'.
# - On BSD sed (default on MacOS), a space is required between -i and '' (or ""): sed -i '' 's/foo/bar/g'.
if [ "$(uname)" = "Darwin" ]; then
# Mac OS X
sed -i '' -e "s/^ENV=.*$/ENV=$environment/g" .env.$environment
else
# Linux and others
sed -i'' -e "s/^ENV=.*$/ENV=$environment/g" .env.$environment
fi
done
fi

0 comments on commit 5419283

Please sign in to comment.