在Android ADB Shell中运行Shell脚本 [英] Running shell script in Android adb shell

查看:1086
本文介绍了在Android ADB Shell中运行Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个脚本,以通过adb shell从Android仿真器中查找并删除我的应用。

I'm trying to create a script to find and remove my app from the Android emulator through the adb shell.

这就是我所拥有的:

adb shell "
cd data/app
for app in com.mycompany.*.apk;
do
    echo $app
    bundle=$(echo $app | sed 's/-[0-9]//g')
    echo 'bundle name is $bundle'
    if [ '$bundle' != '' ];then
        adb uninstall $bundle
    else
        echo 'No apps found'
    fi
done
exit
"

但它似乎没有按预期工作。

But it doesn't seem to work as expected.


  • 我的 for 循环不会重复任何操作。如果我在外壳中完全按照上面的命令手动运行命令,那么它可以工作,但是当我从shellscript运行命令时, for 循环将看不到文件或其他内容。虽然如果我添加 ls,它会正确打印文件夹的内容...因此;

  • echo $ app 打印什么(空字符串)和;

  • echo'捆绑名称为$ bundle'打印捆绑名称为

  • my for loop doesn't iterate through anything. If I manually run the commands exactly as above in the shell, it works, but when I run it from a shellscript then the for loop doesn't see the files or anything. Although if I add an "ls", it prints the contents of the folder correctly... So;
  • echo $app prints nothing (an empty string) and;
  • echo 'bundle name is $bundle' prints bundle name is.

因此,它显然永远不会进入我的if块内,而落入我的else子句中。

Therefore, it obviously never goes inside my if block, falling in to my else clause and that's it.

我做错了什么?我对shell脚本的经验不是很丰富,请多多关照。

What am I doing wrong? I'm not very experienced in shell script, I'd appreciate any ideas.

我的目标是拥有一个shell函数,可以调用它来自动执行从模拟器中删除应用程序的过程,而无需手动拖动和卸载它。

My goal with this is to have a shell function that I can call to automate the process of removing my app from the emulator without having to drag it and uninstall it manually. Other ideas are also very much welcome.

谢谢!

推荐答案

您实际上不应该浏览 / data / app 文件夹。如果要使用单个adb命令卸载名称与 com.mycompany 模式匹配的多个软件包,请使用:

You should not really go through the /data/app folder. If you want to uninstall multiple packages with names matching the com.mycompany pattern with a single adb command use:

adb shell "pm list packages com.mycompany | cut -c9- | xargs -n 1 sh /system/bin/pm uninstall"

这篇关于在Android ADB Shell中运行Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆