Strange “sh” behaviour
-
01-07-2021 - |
Question
I am developing an application on Beaglebone board with Angstrom distrubition fo Linux.I faced an interesting problem.
When I execute :
sh /home/root/Desktop/BBTCP/out/vehicleDetect 192.168.10.29
in terminal it says
/home/root/Desktop/BBTCP/out/vehicleDetect: /home/root/Desktop/BBTCP/out/vehicleDetect: cannot execute binary file
But when i execute
cd /home/root/Desktop/BBTCP/
and
sh out/vehicleDetect 192.168.10.29
it starts working??
What is the reason and why I can't run tha application with first configuration?
I think it is about the difference between ./ and sh. What are the differences?
Solution
My first guess would be that one of the folders in the path /home/root/Desktop/BBTCP
is a link. If vehicleDetect
is a script and it invokes itself recursively, then this link might be confusing it.
If that's not the case, try sh -x /home/root/Desktop/BBTCP/out/vehicleDetect
and see what that prints.
Lastly, check what's in the folder /home/root/Desktop/BBTCP
. There might be an executable sh
in there. If your path contains .
, a different shell might be executed.
OTHER TIPS
Seems like /home/root/Desktop/BBTCP/out/vehicleDetect
is invoking a binary file (an executable) that was built on a different architecture.
The main difference between sh
and ./
is that ./
will attempt to execute the file itself as an executable, whereas sh
will do that for you. It could be that there is a weird magic number at the start of the file, but you would expect sh
to complain about that.
Best guess though it is a #!
line at the start of the file which either contains invalid characters or refers to a strange file. Did you, for example, bring this script file from another operating system (like Windows) that has different line endings? I have seen similar effects when text file scripts have not been converted but just copied. Maybe you downloaded it in a strange format?
Check with od -xc /home/root/Desktop/BBTCP/out/vehicleDetect
and look at the first line.