_wait_for_nbd_connect() and _wait_for_nbd_disconnect() use the variable "i" without declaring it local. Since bash uses dynamic scoping, these functions modify the variable "i" of their caller, or the global variable "i" if the caller did not declare one. Declare "i" and "sz" local to prevent this. Signed-off-by: Bart Van Assche --- tests/nbd/rc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/nbd/rc b/tests/nbd/rc index 6205c4938b7c..9a68c2c9abd4 100644 --- a/tests/nbd/rc +++ b/tests/nbd/rc @@ -42,6 +42,8 @@ _have_nbd_netlink() { } _wait_for_nbd_connect() { + local i sz + for ((i = 0; i < 3; i++)); do sz=$(lsblk --raw --noheadings -o SIZE /dev/nbd0) if [ "$sz" != "0B" ]; then @@ -53,6 +55,8 @@ _wait_for_nbd_connect() { } _wait_for_nbd_disconnect() { + local i + for ((i = 0; i < 3; i++)); do if [[ ! -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then return 0