Android: run a script on non-rooted device

为君一笑 提交于 2020-01-23 12:46:12

问题


Can I run my binary executable file or script bash file on a non-rooted device? 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". I have researched, the reason is Execute permissions on the SDCard is blocked.

Is it possible to run? How can I do that without SU command? I think it is very helpful if somehow can execute any script file.


回答1:


On non-rooted device you can run a script on SDcard with sh command:

    adb shell sh path_to_script_on_sdcard/script.sh



回答2:


Oh, I can run my script without SU permission, just use sh command:

$ cd /sdcard
$ sh helloworld.sh
hello world

I think we cannot do the same with a binary executable file.




回答3:


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:

sh PATH_TO_FILE

Replace PATH with the path of file under /sdcard. It should work.

To run a compatible binary, move the file from sdcard into Termux's home using:

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.



来源:https://stackoverflow.com/questions/36078987/android-run-a-script-on-non-rooted-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!