shell 脚本中调用 adb 出现的奇怪显现象

2022-11-11 19:16:13 +08:00
 hicdn

注释掉 adb 那行,一切正常;

有 adb 那行,外层循环只执行一次。

排查离 bug 一整天,最终确定如下最小复现代码。实际业务是 adb 后面还有别的操作,内层循环检查状态。

➜  /tmp cat tt.sh
while read -r current
do
    # adb shell input tap 1 2
    n=3
    while [ $n -gt 0 ]
    do
        echo $current $n
        n=$((n-1))
        [ $n -eq 1 ] && break
    done
    echo $current done
done < <(echo aa bb cc | tr ' ' '\n')
➜  /tmp bash tt.sh
aa 3
aa 2
aa done
bb 3
bb 2
bb done
cc 3
cc 2
cc done
➜  /tmp cat tt.sh
while read -r current
do
    adb shell input tap 1 2
    n=3
    while [ $n -gt 0 ]
    do
        echo $current $n
        n=$((n-1))
        [ $n -eq 1 ] && break
    done
    echo $current done
done < <(echo aa bb cc | tr ' ' '\n')
➜  /tmp bash tt.sh
aa 3
aa 2
aa done
➜  /tmp
1233 次点击
所在节点    问与答
3 条回复
Senorsen
2022-11-11 20:03:53 +08:00
先无脑 set -x 看看输出
amrnxcdt
2022-11-11 20:36:09 +08:00
试一下包裹下 adb:$(adb shell input tap 1 2)
rrfeng
2022-11-11 21:00:48 +08:00
< /dev/null 也行

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

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

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

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

© 2021 V2EX