spark104
V2EX  ›  问与答

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

  •  
  •   spark104 · Dec 27, 2018 · 2569 views
    This topic created in 2711 days ago, the information mentioned may be changed or developed.

    各位大佬,帮忙解答个问题:
    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
    
    1 replies    2019-07-03 16:04:26 +08:00
    spark104
        1
    spark104  
    OP
       Jul 3, 2019
    已解决:adb shell kill -9 $line 改为 adb shell kill -9 $line < /dev/null
    参考文章: https://www.cnblogs.com/to-be-rich/p/6812897.html
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1072 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 23:41 · PVG 07:41 · LAX 16:41 · JFK 19:41
    ♥ Do have faith in what you're doing.