Sample Header Ad - 728x90

Backup all apks from device using adb: why this loop in bash script doesn't work?

1 vote
2 answers
2472 views
You can do adb shell pm list packages, and after reading through the list, do an adb shell pm path "com.yourpackage" to get the full path and do a simply adb pull. Fact is: I want to automate this. I thought about a really simple bash script: for apk in $(adb shell pm list packages | sed 's/package://g' | sort); do # If you just do an echo, IT WORKS # echo $apk # But here it doesn't work adb shell pm path $apk done But that simply doesn't work. It seems that "$apk" becomes *lost* or something and nothing is shown in that snippet. I don't know if it's a subshell problem, or some peculiarity when using variables that got through an adb shell. Should I create a script apks.sh just using pm list, for and such, push it to my device, run adb shell only once and execute apks.sh?
Asked by Somebody still uses you MS-DOS (727 rep)
Mar 8, 2016, 04:30 AM
Last activity: Jan 2, 2021, 01:46 PM