4

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.

Onik
  • 19,396
  • 14
  • 68
  • 91
Khang .NT
  • 1,504
  • 6
  • 24
  • 46
  • If you don't have execute permissions, you could try to open a shell (`adb shell`) and try `chmod 777 /path/to/helloworld.sh`. I'm not sure if you can do that on a non-rooted device – 0xDEADC0DE Mar 18 '16 at 08:02

4 Answers4

4

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.

Khang .NT
  • 1,504
  • 6
  • 24
  • 46
  • 1
    For executing a binary [How to add more commands to Android Shell?](http://stackoverflow.com/questions/35231168/how-to-add-more-commands-to-android-shell) might be helpful. – Onik Mar 21 '16 at 11:41
3

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

    adb shell sh path_to_script_on_sdcard/script.sh
Onik
  • 19,396
  • 14
  • 68
  • 91
  • the first portion of your command "adb shell" tells me you are running from a PC correct? How can I run the script.sh from the Android device? what do I need? is there an adb.exe in Android 11 OS? I need to run a bunch of "adb shell pm uninstall packagename" among other things, assume device rooted not connect to a PC. Thank you. – Meryan May 18 '22 at 04:33
1

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.

user47
  • 1,080
  • 11
  • 28
0

If you don't have a computer to attach adb on device, try out this app: https://github.com/jarhot1992/Remote-ADB

https://play.google.com/store/apps/details?id=com.github.superadb

But it have some ad popups after several commands executed.

n0099
  • 520
  • 1
  • 4
  • 12