循环从文件中查找应用程序并使用adb shell将其拉出 [英] Loop to find an app from a file and pull it with adb shell
问题描述
我从bash开始,正在编写一个读取文件的脚本,在android设备中搜索每一行的信息(文件的每一行都是设备上安装的应用的名称)>
I'm beginning with bash, I'm writing a script that read a file, search an information in an android device for each line (each line of the file is the name of an app installed on the device)
#!/bin/bash
filename="$1"
while read -r line
do
name="$line"
echo "App : - $name" | adb shell pm path $name
done < "$filename"
这是该脚本的结果
package:/data/app/com.naver.linewebtoon-1/base.apk
package:/data/app/com.game5mobile.lineandwater-2/base.apk
如何获取每个结果行作为其他函数的参数
How can I get each result line as a parameter for an other function
adb shell cat /data/app/com.naver.linewebtoon-1/base.apk > app1.apk
adb shell cat /data/app/com.game5mobile.lineandwater-2/base.apk > app2.apk
推荐答案
echo "App : - $name" | adb shell pm path $name
将调用adb
作为命令,将echo的输出发送到其标准输入.仅仅回显组成的命令将无法实现您的目标.
echo "App : - $name" | adb shell pm path $name
would invoke adb
as a command, sending echo's output to its standard input. That won't achieve your goal of just echoing the composed command.
使用IFS读取文件中的定界数据,并打印出如下组成的命令:
Use IFS to read the delimited data in your file and print out the composed command like this:
#!/bin/bash
filename="$1"
count=0
while IFS=: read -r _ path # ignore the first field by reading it into a dummy variable
do
printf '%s\n' "adb shell cat $path > app$((++count)).apk"
done < "$filename"
这篇关于循环从文件中查找应用程序并使用adb shell将其拉出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!