Bash: Loop until command exit status equals 0

后端 未结 2 897
名媛妹妹
名媛妹妹 2021-02-07 04:53

I have a netcat installed on my local machine and a service running on port 25565. Using the command:

nc 127.0.0.1 25565 < /dev/null; echo $?
<
2条回答
  •  野性不改
    2021-02-07 05:11

    You could try something like

    while true; do
        nc 127.0.0.1 25565 < /dev/null
        if [ $? -eq 0 ]; then
            break
        fi
        sleep 1
    done
    echo "The command output changed!"
    

提交回复
热议问题