linux - bash shell while loop无法break
黄舟
黄舟 2017-04-17 12:01:12
0
1
714

为什么这个while循环执行完echo while00 && echo while01后不break

while $(sleep 0.5); do pgrep -f baidu > /dev/null 2>&1 || (echo while00 && echo while01 && break); done

监听进程退出后,执行后面的命令
比如ping -c 10 -i 1 baidu.com

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
刘奇

(...) creates a subshell, so break doesn't work.

In fact, according to the intention of your code, it is completely fine not to write brackets here. Just remove the brackets.

P.S. The while $(sleep 0.5) you wrote earlier is a misuse of the shell command. You should write while sleep 0.5 here, and adding a $ is unnecessary.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!