I have some python file in windows, and I transfer them to my gentoo by samba.
I check their mode is executable, and I use ./xxx.py to run it, but get an error:
: No such file or directory
I am troubled that it does not prompt what file is not here.
but when I use python xxx.py, it can run in the right way.
and then I check the CR character by use set ff in vim, and found it is dos, then I use set ff=unix to set it, now it can run by using ./xxx.py
but I don’t know why it can be use python xxx.py when ff=dos?
DOS files ends lines with CR+LF, Unix files just with LF. This means that when Unix reads your file to figure out what the executable name is, that executable’s name ends in CR. Like so:
When I run that I get:
What happens in your case is that the CR character (the ^M above) is not printed out but “executed” by your terminal, i.e., the cursor will return to the start of the line. Hence, everything before the ^M is overwritten:
: bad interpreter: No such file or directory
This is why you can’t execute files with DOS file ending on Unix.
Any even remotely modern source control system will handle this for you, and change the file endings when you check out the source.