You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bash脚本执行exec adb卸载命令后提前退出,无法执行后续逻辑

问题原因与解决方案

嘿,你遇到的这个问题核心是**exec命令的使用方式不对**!

为什么脚本会提前退出?

exec命令的作用是用指定的程序替换当前的shell进程——也就是说,当你执行exec adb uninstall...时,你的脚本进程直接被adb命令替换了,adb执行完成后,这个进程就结束了,自然没办法回到脚本继续执行后面关于Google Duo的逻辑。

怎么解决?

很简单,把所有的exec去掉就行!直接执行adb命令,它会在脚本的子进程中运行,执行完毕后会回到脚本继续往下走。

另外我还发现脚本里有个小笔误:read -p "Would you like to delete Google Duo? (yes/no) " DUO#里的#是多余的,会导致变量名异常,我也一起帮你修正了。

修改后的完整脚本如下:

#!/bin/bash
read -p "Would you like to delete Google Drive? (yes/no) " DRIVE
if [ "$DRIVE" == "yes" ]
then
    echo "Google Drive will be deleted."
    adb uninstall --user 0 com.google.android.apps.docs
elif [ "$DRIVE" == "no" ]
then
    echo "Google Drive will not be deleted."
else
    echo "It's a yes or no question!"
fi
read -p "Would you like to delete Google Duo? (yes/no) " DUO
if [ "$DUO" == "yes" ]
then
    echo "Google Duo will be deleted."
    adb uninstall --user 0 com.google.android.apps.tachyon
elif [ "$DUO" == "no" ]
then
    echo "Google Duo will not be deleted."
else
    echo "It's a yes or no question"
fi

内容的提问来源于stack exchange,提问作者computernoob14

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:02:14