[英]Android: run a script on non-rooted device
Can I run my binary executable file or script bash file on a non-rooted device? 我可以在非root用户的设备上运行二进制可执行文件或脚本bash文件吗? I have a small script like this:
我有一个像这样的小脚本:
#helloworld.sh
echo "hello world"
I saved it in /sdcard
and try to run, but i got "Permission denied" . 我将其保存在
/sdcard
并尝试运行,但是出现“权限被拒绝”的提示 。 I have researched, the reason is Execute permissions on the SDCard
is blocked. 我已经研究过,原因是
SDCard
执行权限被阻止。
Is it possible to run? 可以跑步吗? How can I do that without
SU
command? 没有
SU
命令怎么办? I think it is very helpful if somehow can execute any script file. 我认为如果可以执行任何脚本文件将非常有帮助。
在非root用户的设备上,可以使用sh
命令在SDcard
上运行脚本:
adb shell sh path_to_script_on_sdcard/script.sh
Oh, I can run my script without SU permission, just use sh command: 哦,我可以在没有SU许可的情况下运行脚本,只需使用sh命令:
$ cd /sdcard
$ sh helloworld.sh
hello world
I think we cannot do the same with a binary executable file. 我认为我们无法对二进制可执行文件执行相同的操作。
For a shell script you can setup Termux or Terminal Emulator in your phone, enable Storage permission for it, launch it and than run the script like this: 对于外壳程序脚本,您可以在手机中设置Termux或Terminal Emulator , 为其启用存储权限,启动它,然后运行脚本,如下所示:
sh PATH_TO_FILE
Replace PATH with the path of file under /sdcard. 将PATH替换为/ sdcard下文件的路径。 It should work.
它应该工作。
To run a compatible binary, move the file from sdcard into Termux's home using: 要运行兼容的二进制文件,请使用以下命令将文件从sdcard移至Termux的主目录:
mv PATH_TO_FILE $HOME
Then verify and enable, using chmod +x $HOME/FILENAME
if necessary, the executable permission on that moved file and run it. 然后根据需要使用
chmod +x $HOME/FILENAME
验证并启用该已移动文件的可执行权限并运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.