shell 脚本: while read 的循环体中,如果有 adb shell,则只会执行一次

2018-12-27 16:38:20 +08:00
 spark104

各位大佬,帮忙解答个问题:
shell 脚本: while read 后的do done 循环体中,如果有 adb shell 就只会执行一次就跳出循环,如果是其他 shell 命令则可以正常执行多次循环,那怎么让 adb shell 也正常执行多次?

adb shell ps | grep "mediaserver\|drmserver" | grep -v "grep" | awk '{print $2}' | while read line
do
    adb shell kill -9 $line  # 只执行一次就会跳出循环
    #ls | grep Server    # 比如 line 有 3 行,则会正常执行 3 次才跳出循环
    echo "kill" $line
done
1855 次点击
所在节点    问与答
1 条回复
spark104
2019-07-03 16:04:26 +08:00
已解决:adb shell kill -9 $line 改为 adb shell kill -9 $line < /dev/null
参考文章: https://www.cnblogs.com/to-be-rich/p/6812897.html

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/521578

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX