summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>2017-10-19 22:59:17 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-10-19 22:59:17 +0000
commitc132eb192e4c2b49dc37a6d9f22dfd86caa3ddbd (patch)
treeacdb18340b56b1a82cdccd24ba7a261bd8a92e85
parentea5f65b10e4530f4ecc2ea2a13e87f7998899366 (diff)
parenta05761b9a0cafa01fc837798e030cf01f46026c3 (diff)
Merge "lib.sh: Fix locals override in nested invocations" into stable/euphratesopnfv-5.0.RC1opnfv-5.0.0
-rw-r--r--mcp/scripts/lib.sh25
1 files changed, 14 insertions, 11 deletions
diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh
index da129a7da..a165bb367 100644
--- a/mcp/scripts/lib.sh
+++ b/mcp/scripts/lib.sh
@@ -191,15 +191,18 @@ function parse_yaml {
}
function wait_for {
- local total_attempts=$1; shift
- local cmdstr=$*
- local sleep_time=10
- echo "[NOTE] Waiting for cmd to return success: ${cmdstr}"
- # shellcheck disable=SC2034
- for attempt in $(seq "${total_attempts}"); do
- # shellcheck disable=SC2015
- eval "${cmdstr}" && return 0 || true
- echo -n '.'; sleep "${sleep_time}"
- done
- return 1
+ # Execute in a subshell to prevent local variable override during recursion
+ (
+ local total_attempts=$1; shift
+ local cmdstr=$*
+ local sleep_time=10
+ echo "[NOTE] Waiting for cmd to return success: ${cmdstr}"
+ # shellcheck disable=SC2034
+ for attempt in $(seq "${total_attempts}"); do
+ # shellcheck disable=SC2015
+ eval "${cmdstr}" && return 0 || true
+ echo -n '.'; sleep "${sleep_time}"
+ done
+ return 1
+ )
}