ADB - 如何检查文件是否包含字符串
ADB - how to check if file contains a string
我正在尝试编写一个 zsh 脚本来检查文件是否包含特定字符串。
我无法克服的困难是文件在 Android 设备上,而我正在 Mac 上执行脚本。
这是我写的(如果文件也在 Mac 上,则有效)
if grep -q SpecificString "Desktop/file.json"
then
echo found
else
echo not found
fi
假设我想在 Android (storage/self/primary/file.json)
上的文件中检查 SpecificString
我该怎么做?
一个可能的脚本如下:
#!/bin/zsh
adb shell grep "SpecificString" /sdcard/file.json
if [ $? -eq 0 ]; then
echo "string found"
else
echo "string not found"
fi
当然要根据自己的需要进行扩展
一种可能的解决方案是使用 adb
将脚本复制到您的 Android 设备。然后你可以在设备上使用 adb shell
和 运行 脚本直接在设备上获得 shell
我正在尝试编写一个 zsh 脚本来检查文件是否包含特定字符串。
我无法克服的困难是文件在 Android 设备上,而我正在 Mac 上执行脚本。
这是我写的(如果文件也在 Mac 上,则有效)
if grep -q SpecificString "Desktop/file.json"
then
echo found
else
echo not found
fi
假设我想在 Android (storage/self/primary/file.json)
上的文件中检查 SpecificString我该怎么做?
一个可能的脚本如下:
#!/bin/zsh
adb shell grep "SpecificString" /sdcard/file.json
if [ $? -eq 0 ]; then
echo "string found"
else
echo "string not found"
fi
当然要根据自己的需要进行扩展
一种可能的解决方案是使用 adb
将脚本复制到您的 Android 设备。然后你可以在设备上使用 adb shell
和 运行 脚本直接在设备上获得 shell