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
forloop 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 theforloop doesn't see the files or anything. Although if I add an "ls", it prints the contents of the folder correctly... So; echo $appprints nothing (an empty string) and;echo 'bundle name is $bundle'printsbundle 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!