adb shell 执行sh脚本_在Android ADB Shell中运行Shell脚本

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

This is what I've got:

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.

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.

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

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

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.

Thanks!

解决方案

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"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值