JackWM
JackWM

Reputation: 10535

Copy apk files in a bash script

I tried the following script written by me.

#!/bin/bash
adb -s 015d2578a7280412 shell ls /data/app > apps.txt 
while read line
do
    apk=/data/app/$line
    adb -s 015d2578a7280412 pull $apk apk-nexus7-default
done < apps.txt

I got errors like:

' does not existdata/app/com.StudioOnMars.CSPortable-1.apk
' does not existdata/app/com.adobe.reader-1.apk
...

When I tried

adb -s 015d2578a7280412 pull /data/app/com.adobe.reader-1.apk apk-nexus7-default

It worked.

Any problem with the piece of scripts?

Upvotes: 0

Views: 794

Answers (2)

Alex P.
Alex P.

Reputation: 31666

It's a known issue with adb - that even in linux it is using MSDOS style newline characters - CR+LF ('\r\n') instead of just LF ('\n').

The easiest way to mitigate that is to remove '\r' from the adb output

adb -s 015d2578a7280412 shell ls /data/app | tr -d '\r'> apps.txt

Upvotes: 1

Diego Torres Milano
Diego Torres Milano

Reputation: 69188

Just do:

$ adb  -s 015d2578a7280412 pull /data/app/

pull: building file list...
pull: /data/app/some.apk -> ./some.apk
...

Upvotes: 0

Related Questions