ADB uninstalls all installation packages shell command appears command not found: ^M

background

On MAC and CentOS, I want to write a script to uninstall all installation packages. The
script is as follows:

for line in $(adb  shell pm list packages -3|awk -F ':' '{print $2}')
do
    echo "line is: $line"
    adb uninstall line
done

Appears when executing shell commands

line is: adb uninstall  com.example.android.apis
zsh: command not found: Failure^M

reason

The specific reason is that there are characters ^M (Ctrl-M) that are not recognized by linux, and these characters need to be removed.

Solution

use td to delete these characters

tr -d '\r'

Final script:

for line in $(adb shell pm list packages -3|awk -F ':' '{print $2}'|tr -d '\r')
do
    echo "line is: adb uninstall  $line"
    adb  uninstall  $line
done

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326518294&siteId=291194637