From 869a9b3ae7135158247113921c2dfc6cbe7ad6ce Mon Sep 17 00:00:00 2001 From: Dimitrios Apostolou Date: Wed, 2 Oct 2019 19:05:15 +0200 Subject: Fix shell function is_script_executed It used to return error when tested inside a login shell, because $0 is "-bash" and `basename` was trying to interpret -b as an option. Change-Id: I5faa2dc01e50c7d5bcfc0ab1fcfd910b2538afc2 Reviewed-by: Heikki Halmet --- coin/provisioning/common/unix/common.sourced.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coin/provisioning/common/unix/common.sourced.sh b/coin/provisioning/common/unix/common.sourced.sh index 7fb267a6..aca5dd04 100644 --- a/coin/provisioning/common/unix/common.sourced.sh +++ b/coin/provisioning/common/unix/common.sourced.sh @@ -65,8 +65,10 @@ fatal () { fi } +# Takes one argument which should be the filename of this script. Returns true +# if the script is being sourced, false if the script is being executed. is_script_executed () { - [ x"$(basename "$0")" = x"$1" ] + [ x"$(basename $(echo "$0" | sed s/^-//))" = x"$1" ] } -- cgit v1.2.3