3

I am trying to uninstall multiple packages using a bash script with adb uninstall.

In theory following scripts should work:

adb shell pm list packages com.your.app |
cut -d ':' -f 2 | while read line ; do
  adb uninstall --verbose $line
done

OR

adb shell pm list packages com.your.app |
cut -d ':' -f 2 |
xargs -L1 -t adb uninstall

I get the following error

Failure [DELETE_FAILED_INTERNAL_ERROR]

I also found that the problem is with adb commands not taking piped arguments or arguments from shell variables. For example the following command also

echo com.your.app | adb uninstall

This will also give the same error.

I have already looked at delete packages of domain by adb shell pm

tripleee
  • 175,061
  • 34
  • 275
  • 318
Ubaier Bhat
  • 854
  • 13
  • 33

1 Answers1

5

\r is added added to the output from the first command. We can use tr -d '\r' to remove these characters.

adb shell pm list packages com.your.app |
cut -d ':' -f 2 |
tr -d '\r' |
xargs -L1 -t adb uninstall

Found the solution in Echo outputting results in erratic order in BASH

tripleee
  • 175,061
  • 34
  • 275
  • 318
Ubaier Bhat
  • 854
  • 13
  • 33
  • 1
    The symbolic notation `'\r'` is not portable, though it should generally work with `tr` on Linux. For a portable notation, try `'\015'`. – tripleee Apr 04 '18 at 04:47