Skip to content

hack/update-estimator-protobuf.sh: sed -r flag incompatible with macOS BSD sed #7278

@Krishiv-Mahajan

Description

@Krishiv-Mahajan

Fix sed -rsed -E for macOS compatibility in update-estimator-protobuf.sh

Part of #7269

Problem

Line 47 of hack/update-estimator-protobuf.sh uses sed -r to extract the protoc major version:

if [[ -z "$(which protoc)" || $(protoc --version | sed -r "s/libprotoc ([0-9]+).*/\1/g") -lt 3 ]];

-r is a GNU sed flag and is not recognized by BSD sed, which ships with macOS. Running this script on macOS produces:

sed: illegal option -- r

Since this is inside an if condition at the very start of the script, it aborts immediately — before even checking if protoc is installed.

Fix

Replace -r with -E. The regex pattern itself is unchanged.

# Before (GNU sed only)
protoc --version | sed -r "s/libprotoc ([0-9]+).*/\1/g"

# After (BSD + GNU sed)
protoc --version | sed -E "s/libprotoc ([0-9]+).*/\1/g"

-E is the POSIX standard flag for extended regex and is supported by both BSD sed (macOS) and GNU sed (Linux, since 4.2 / 2012).

Testing

Verified on macOS (Apple Silicon) — script no longer aborts with illegal option error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions