0

I've got a simple Python program which has the correct Shebang line to start with:

#!/usr/bin/env python
from __future__ import division
import math
etc.

When I run the file with python before it, it works like a charm:

$ python current_steer.py
works perfect!

But when I run the same program using the dot slash notation, I get this:

$ ./current_steer.py
: No such file or directory
$

I'm 100% sure the file name is correct. I copy pasted it and also had it finish using tab. All other Python scripts I've got are running fine using the dot slash notation so I have no idea why this wouldn't work.

I'm running this on a Raspberry Pi with an up to date Raspbian install.

Does anybody know why this one specific script wouldn't run using the dot-slash notation? All tips are welcome!

kramer65
  • 50,427
  • 120
  • 308
  • 488
  • 2
    Your file has DOS newlines. Use `dos2unix`, or if your editor is `vim`, run `:set fileformat=unix` before saving it. – Charles Duffy Apr 18 '17 at 19:28
  • 1
    What's happening is that your first line is actually `$'#!/usr/bin/env python\r'` where `$'\r'` is a CR, which sends the cursor to the beginning of the line when it's printed. – Charles Duffy Apr 18 '17 at 19:30
  • I would look for invisible unicode characters (or unicode characters that look exactly like ASCII ones) including [BOM](https://en.wikipedia.org/wiki/Byte_order_mark). You may want to open the file in an hex editor. – Paulo Scardine Apr 18 '17 at 19:30
  • 1
    Thus, `python$'\r': No such file or directory` becomes just `: No such file or directory`, because the cursor is sent back to the front of the line just before printing the `:` – Charles Duffy Apr 18 '17 at 19:30
  • @CharlesDuffy - Awesome, thanks! That was it! If you add your comment as an answer I can accept it. And one last question; how did you know? Does this happen more often? Because I really had no idea how to debug this.. – kramer65 Apr 18 '17 at 19:31
  • `cp current_steer.py current_steer.py-bak ; sed -i 's/\r//' current_steer.py` should fix it. – l'L'l Apr 18 '17 at 19:31
  • @PauloScardine, this one's very specifically a CR -- if you had other nonprinting characters they wouldn't be causing the cursor movement that's hiding the `python` name from being printed. – Charles Duffy Apr 18 '17 at 19:31
  • @kramer65, actually, I already closed this as a duplicate of a preexisting question (which I found by googling the search string `site:stackoverflow.com python ": No such file or directory" running script`). – Charles Duffy Apr 18 '17 at 19:32

0 Answers0