Lately I've been playing around with .sh scripting in Android. At first I used BusyBox and it's integrated scripting utility, though I quickly realised that coding on the phone isn't the best, so I switched over to my desktop and started using ADB to push my scripts to my device. It all worked well for about two weeks, until recently the exact same scripts that used to work perfectly, tell me some : not found[0]: syntax error: '{
Error. I've copied the exact same code from my script and used BusyBox to create it for me, and that way it works just fine. So the code is fine.
After some digging, I think it's either because of permissions, because of encoding possibly, or also because of the location of the scripts. I've tried many different locations (because I want to be able to run the scripts without root), and ended up choosing /storage/emulated/0
. If I understood correctly, this is a symlink to the internal storage, which is read/write-able without root. But maybe sometimes executable and sometimes not? I don't know.
So my question is as following: What is the best location on an Android Device to run scripts without root from? Preferably a path that works on any android device.
Info:
- Rooted Samsung S7 SM-G930F
- Android 8.0.0
- I'm using
#!/system/bin/sh
inside the .sh files - I'm running the scripts with
sh script.sh
- When trying to run it as an executable
./script.sh
, I get aPermission denied
error. With or without root.
PS: And if anyone has a clue to why the exact same scripts stopped working out of nowhere, I'd be happy to know!
UPDATE: Thanks to @IrfanLatif, I've managed to fix the : not found[0]: syntax error: '{
Error! I was using Visual Studio Code as my editor for the scripts, which was saving them with the End of Line Sequence CRLF
, which Android doesn't like. For an easy fix, just change your Line Endings to LF
, problem solved. Check the comments out for more info.