Skip to content

Bug: sed -i behaves differently on macOS and Linux, causing script failures #2832

Open
@nintran52

Description

@nintran52

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 using sed

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions