mk.. mk.. - 24 days ago 8
Linux Question

Unable to execute a shell script in android shell

I am trying tun a shell script from android shell.
Please see the output below.

root@user:/data # ./run_script.sh
/system/bin/sh: ./run_script.sh: No such file or directory

root@user:/data # ls -l run_script.sh
-rwxrwxrwx root root 5861 2016-11-14 07:31 run_script.sh


Why is it saying "No such file or directory" The error is strange as the file is actually present.

I tried copying the same shell script to /system parition as well. The result is same. I verified from ount command that both the partitions are not mounted with
noexec
flag.

I am able to get it working with
sh run_script
but I want to get it working by executing directly.

Answer

Usually this happens when a shebang is not correct. Check if you have a "#!..." at the start of the script and remove it or correct it