Open
Description
What were you trying to achieve?
I wanted to replace environment variable values in an .env
file using sed -i
in a script that processes secrets from a file. The goal was to automatically update keys like SMQ_VAULT_UNSEAL_KEY_1
, SMQ_VAULT_TOKEN
, etc., based on parsed values from secrets
.
What are the expected results?
The script should:
-
Run correctly across macOS, Linux, and CI environments
-
Replace values in-place inside the
.env
file usingsed
-
Not generate any errors regardless of operating system
What are the received results?
macOS error:
sed: 1: "docker/.env": extra characters at the end of d command
Steps To Reproduce
Run:
bash ./docker/addons/vault/scripts/vault_copy_env.sh
In what environment did you encounter the issue?
- OS: macOS Sonoma (14.7.5)
Additional information you deem important
- The solution is to detect OS type using uname and conditionally apply:
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' ...
else
sed -i ...
fi