0

Hi I have this script to debloat my phone:

#!/bin/bash

adb devices
sleep 1

cat packagelist.txt | while read line 
do  
    echo removing $line
    adb shell pm uninstall --user 0 $line 
done

and packagelist.txt is something like

com.miui.miwallpaper
com.miui.cloudservice
com.miui.notes

with the new line at the end. If I comment the line with adb shell etc.. it kindly prints all the lines of the file as should be but otherwise it only excecutes the command with the first package and then exits. The first package is already uninstalled so it gives an error but I'd like to ignore them and continue the loop. I tried also without the loop hardcoding the package name in adb shell etc... and this continues even if the first gives an error.

1 Answers1

-1

Can you try this?

I have the feeling the while loop is not able to consume stdin correctly.

#!/bin/bash

adb devices
sleep 1

for line in  $( cat packagelist.txt ) 
do  
    echo removing $line
    adb shell pm uninstall --user 0 $line 
done

Let me know if it works.

Matias Barrios
  • 4,674
  • 3
  • 22
  • 49