I got a while
loop in a Bash script which looks something like this
#!/bin/bash# do something with kubectl port-forwardwhile ! nc -vz localhost "$port" > /dev/null 2>&1 ; do # echo sleeping sleep 0.1done#access ressource on the port-forwarded website
which basically is supposed to be waiting until a kubectl port-forward
command has succesfully started.
However, executing the script under Git Bash (I execute via MSYS_NO_PATHCONV=1 bash
) leads to an infinite loop, as it never exits the while
loop. I installed ncap and the nc command nc -vz localhost $port
works on its own fine. Executing with -x
shows that it is looping over the nc
command which is running successfully.
Executing the same script in Ubuntu WSL, it just works, exits the while
loop as intended and continues.