为什么这个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
人生最曼妙的风景,竟是内心的淡定与从容!
(...) creates a subshell, so break doesn't work.
(...)
break
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.
while $(sleep 0.5)
while sleep 0.5
$
(...)
creates a subshell, sobreak
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 writewhile sleep 0.5
here, and adding a$
is unnecessary.