Script file "command not found"

Good day. I'll try to explain as best as possible even if I am using an automatic translation. I have a problem on a system with FreeBSD sh() scripts. The files are loaded via a ZIP archive, unpacked and set via chmod and property owner in 0755. At this point, the file should be executable, and instead of trying to run it returns an error command not found. To make the script executable has identified that it is necessary to open it (with vi() or another editor) and save it again, even without any change in its entirety. At the next attempt to launch, the execution is successful.

The question is why? I cannot understand what I do is that simply saving the file before this becomes executable when it is not.

Thanks, I'm going crazy.
 
windstyle said:
At this point, the file should be executable, and instead of trying to run it returns an error "command not found"
Look at the first line of the script, the so-called "she-bang". It's very likely it's pointing to an interpreter that either doesn't exist or is in a different place on FreeBSD.
 
Thank you for your response. The first line of the script reads
Code:
#!/bin/sh
as an interpreter that is correct. Moreover, I repeat that the file is changed from "command not found" to the "executable" only by opening it with a text editor and save, without changing any part thereof.
 
Does the file work as expected when run like /bin/sh /full/path/to/file? edit: Meant without the open and save step, just after unziping from archive.

May be some strange non-printable characters in such file, which may be silently converted during display in the editor? Different line endings between UNIX and Windows systems comes on my mind as first usual suspect.
 
Maybe it's a newline issue (CRLF vs LF)? Does file yourscriptsname mention something about "CRLF"?

Code:
% file testscript.sh
testscript.sh: POSIX shell script, ASCII text executable, with CRLF line terminators
% ./testscript.sh 
./testscript.sh: Command not found.
% cp testscript.sh testscript.sh.crlf
% tr -d '\r' <testscript.sh.crlf >testscript.sh
% file testscript.sh
testscript.sh: POSIX shell script, ASCII text executable
% ./testscript.sh
Woohoo! :)
%
 
@worldi is right, I'd bet on it. I thought of that just now and came back to this thread... too late. :)
 
Last edited by a moderator:
Hi.

Thank you to all for the answer. I will try the variety of solutions and supply feedback to you. About the Windows Vs Linux CRLF, the script was written on freebsd FreeBSD for breebsd FreeBSD, but during the time the file was network-copied to Windows and another time from Windows to freebsd FreeBSD; I don't know if this can alter the file, probably. I will check.

Thanks a lot, see you later.
 
OK, before some test, yes. The problem was caused by a WinSCP file copy from Linux to Windows and from Windows to Linux.

Thanks to all, bye bye.
 
Back
Top