4

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 partition as well. The result is same. I verified from mount 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.

3
  • does a file have required permissions? (execute) Commented Nov 14, 2016 at 8:29
  • Yes 777 are the permissions. In the code snippet i showed the permissions Commented Nov 14, 2016 at 8:30
  • oh, right, sorry, I've missed it Commented Nov 14, 2016 at 8:31

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

9 Comments

I have #!/bin/sh I tried changing it to #!/bin/bash.. Both ways the result is same
you have to remove it or put: "#!/system/bin/sh" (no quotes)
Thank you so much. It worked.. I have one more query.. My script is a big one. In the middle of execution I see an error as follows "./run_script: //: can't execute: Is a directory" error. Any Idea why do we see this
Looks line it's trying to execute a directory, you might want to run it as "sh -x run_script.sh" : "-x xtrace Write each command to standard error (preceded by a ‘+ ’) before it is executed. Useful for debugging.his will print out in "debug" mode" and see exactly what's going on.
Thanks A lot rift85. You have saved me a lot time.
|
0

file format reason maybe you create file in windows,then push it to phone. cat command ,can not see it. use vi,we can see

!/bin/sh^M

ps^M

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.