84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
为什么这个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.