From 4847ff77fd02c67f994b09f53babcbe5086b07dd Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 8 Feb 2024 22:35:49 -0500 Subject: [PATCH] tests/utils/env.sh.in: make it portable for Bash and Zsh The syntax ${!varname:-} isn't valid in Zsh. To make it possible to source the generated `env.sh` interactively, make this (more) portable. Now _set_var_def() also sets if the variable is set but empty, but I don't think it's an issue here. Signed-off-by: Philippe Proulx Change-Id: I07d49199c403ac24d569d383fd8bde2cf5b668e6 Reviewed-on: https://review.lttng.org/c/babeltrace/+/11769 --- tests/utils/env.sh.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/utils/env.sh.in b/tests/utils/env.sh.in index 12069fef..4cd75ce1 100644 --- a/tests/utils/env.sh.in +++ b/tests/utils/env.sh.in @@ -3,12 +3,13 @@ # SPDX-FileCopyrightText: 2021-2022 EfficiOS, Inc. # SPDX-License-Identifier: GPL-2.0-only -# Sets the variable named `$1` to `$2` if it's not set, and exports it. +# Sets the variable named `$1` to `$2` if it's not set (or empty), and +# exports it. _set_var_def() { local -r varname=$1 local -r val=$2 - if [[ -z ${!varname:-} ]]; then + if [[ -z $(eval echo "\$$varname") ]]; then eval "$varname='$val'" fi -- 2.34.1