How to solve “bad interpreter: No such file or directory”

前端 未结 6 1253
礼貌的吻别
礼貌的吻别 2021-01-31 08:12

I\'m trying to run a sh script and get the following error on Mac:

/usr/bin/perl^M: bad interpreter: No such file or directory

How

相关标签:
6条回答
  • 2021-01-31 08:32

    Remove ^M control chars with

    perl -i -pe 'y|\r||d' script.pl
    
    0 讨论(0)
  • 2021-01-31 08:39

    You seem to have weird line endings in your script: ^M is a carriage return \r. Transform your script to Unix line endings (just \n instead of \r\n, which is the line ending on Windows systems).

    0 讨论(0)
  • 2021-01-31 08:43

    /usr/bin/perl^M:

    Remove the ^M at the end of usr/bin/perl from the #! line at the beginning of the script. That is a spurious ASCII 13 character that is making the shell go crazy.

    Possibly you would need to inspect the file with a binary editor if you do not see the character.

    You could do like this to convert the file to Mac line-ending format:

    $ vi your_script.sh
    

    once in vi type:

     :set ff=unix
    
     :x
    
    0 讨论(0)
  • 2021-01-31 08:46

    And if you prefer Sublime Text - simply go to View -> Line Endings and check Unix.

    0 讨论(0)
  • 2021-01-31 08:51

    The problem is that you're trying to use DOS/Windows text format on Linux/Unix/OSX machine.

    In DOS/Windows text files a line break, also known as newline, is a combination of two characters: a Carriage Return (CR) followed by a Line Feed (LF). In Unix text files a line break is a single character: the Line Feed (LF).

    Dos2unix can convert for you the encoding of files, in example:

    dos2unix yourfile yourfile
    

    For help, run: man dos2unix.

    0 讨论(0)
  • 2021-01-31 08:58

    An alternative approach:

    sudo ln -s /usr/bin/perl /usr/local/bin/perl`echo -e '\r'`
    
    0 讨论(0)
提交回复
热议问题