1

While running a file entitled shuf.py in the linux environment, I run into this following error

./shuf.py -e cats and dogs
-bash: ./shuf.py: /usr/bin/python^M: bad interpreter: No such file or directory

But when i do the same thing as below, it works fine python shuf.py -e cats and dogs

I appended my PATH so that it is correct and the first line of my code is #!/usr/bin/python

I'm not sure what the problem is?

Simon D
  • 5,730
  • 2
  • 17
  • 31
  • 4
    Looks like your script has the wrong line endings (saved on a windows machine?). You can use `tr` to translate, e.g. `tr -d '\r' < shuf.py > shuf-new.py` – AChampion Apr 28 '18 at 18:38
  • 1
    use the dos2unix command line utility to convert your script – What Apr 28 '18 at 18:38
  • The tr command makes it work! But i also have to make sure that the code works with Python3, and when i change the first line to #!/usr/bin/python, I get the error that -bash: ./shuf-new.py: /usr/bin/python3: bad interpreter: No such file or directory – Devam Shroff Apr 28 '18 at 18:48
  • 1
    Possible duplicate of [Python code from Windows to Linux](https://stackoverflow.com/q/30884008/608639), [How to change end-of-line conventions?](https://stackoverflow.com/q/41369772/608639), [Python script gives `: No such file or directory`](https://stackoverflow.com/q/19764710/608639), etc – jww Apr 28 '18 at 20:56

0 Answers0