我有一个bash脚本,如下所示
if [ -f "/sdcard/testfile"]
then
echo "exists" > /sdcard/outfile
else
echo "does not exist" > /sdcard/outfile
fi我有足够的权限使用/system/bin/sh运行这个程序。我从我的应用程序中调用这个脚本,并使用/system/bin/sh运行这个脚本。但是在运行之后,即使文件'/sdcard/testfile‘存在,我也会变得错误。当我显式地在adb shell中运行时,我会得到这个错误。
[: not found还有其他方法来完成这个任务吗?由于应用程序的权限问题,我不能只使用java.io.File;因此,我坚持shell脚本(命令)。
我需要应用程序本身的输出。我是说,
if(filesAreAvailable)
executeSomething();
else
executeSomethingElse();基本上,我是以编程方式在/data/data/myPackageName/files目录中编写这个脚本,并调用命令:
if [ -f "/sdcard/testfile"]作为
fileWriterScript.write("if [ -f \"/sdcard/testfile\" ]\n")发布于 2018-08-13 17:46:08
我用了这个剧本。它在检查手机上是否存在文件。
#!/bin/bash
RESULT=$(adb shell "[ -f $1 ] || echo 1")
if [ -z "$RESULT" ]; then
echo "File exists!"
else
echo "File not found!"
fihttps://stackoverflow.com/questions/25805401
复制相似问题