Skip to content

Commit 1fc9f70

Browse files
authored
Merge pull request #176 from orestisfl/fix-demo-linux
fix: demo: make sed command compatible with both GNU and BSD sed
2 parents f7f0465 + 0e54e54 commit 1fc9f70

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

demo.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ DOCKER_COLLECTOR_CONFIG_CLOUD='./src/otel-collector/otelcol-elastic-config.yaml'
2424
DOCKER_COLLECTOR_CONFIG_SERVERLESS='./src/otel-collector/otelcol-elastic-otlp-config.yaml'
2525
COLLECTOR_CONTRIB_IMAGE=docker.elastic.co/elastic-agent/elastic-agent:$ELASTIC_STACK_VERSION
2626

27+
# Detect sed variant: GNU sed uses --version, BSD sed doesn't
28+
# GNU sed: sed -i (no empty string needed)
29+
# BSD sed: sed -i '' (empty string required)
30+
if sed --version >/dev/null 2>&1; then
31+
SED_IS_BSD="false"
32+
else
33+
SED_IS_BSD="true"
34+
fi
35+
36+
# Portable sed in-place editing function
37+
# Usage: sed_in_place "s/pattern/replacement/g" file
38+
sed_in_place() {
39+
if [ "$SED_IS_BSD" = "true" ]; then
40+
sed -i '' "$@"
41+
else
42+
sed -i "$@"
43+
fi
44+
}
2745

2846
# Variables
2947
deployment_type=""
@@ -60,7 +78,7 @@ update_env_var() {
6078
VAR="$1"
6179
VAL="$2"
6280
if grep -q "^$VAR=" "$ENV_OVERRIDE_FILE"; then
63-
sed -i '' "s|^$VAR=.*|$VAR=\"$VAL\"|" "$ENV_OVERRIDE_FILE"
81+
sed_in_place "s|^$VAR=.*|$VAR=\"$VAL\"|" "$ENV_OVERRIDE_FILE"
6482
else
6583
echo "$VAR=\"$VAL\"" >> "$ENV_OVERRIDE_FILE"
6684
fi
@@ -241,4 +259,4 @@ main() {
241259
echo "🎉 OTel Demo and EDOT are running on '$platform'; data is flowing to Elastic ($deployment_type)."
242260
}
243261

244-
main "$@"
262+
main "$@"

0 commit comments

Comments
 (0)