开发者

Shebang #! unrecognized in Ubuntu, File created in Windows7 | Troubleshoot encoding

Basically, the file was bro开发者_如何学运维ken some where along the way from Windows7 to Ubuntu.

How can I look at a binary representation of the file to see what happened?


PHP command line script still have to have the <?php opener in them.

#!/usr/bin/php
echo "hi mom!\n";

will not work, it has to be

#!/usr/bin/php
<?php
    echo "hi mom!\n";

This is because there's no such thing as a "php script". There are only various text files that have PHP code blocks embedded within them. Even in CLI mode, PHP expects/requires to see at least one <?php block. Otherwise the interpreter won't kick in and won't see any of the code, even though you've stated it's a PHP script with the shebang.

PHP cli mode is basically a hacked-in afterthought. PHP started out as a server-side CGI script parser and has not fundamentally changed from that mode.


Did you run with a ./?

IE:

./myscript.php


Try opening it with vi(m) and you'll see the problem. It's a bad intepreter (^M) at the end of each line. Try converting it (fromdos or dos2unix), this shoul'd fix the problem ;-)


My guess is that the files created on Windows have a BOM that is confusing matters.


When using Notepad++ on a Windows machine, one can change the EOL character from Windows to UNIX by going to

Edit > EOL Conversion > UNIX format

Shebang #! unrecognized in Ubuntu, File created in Windows7 | Troubleshoot encoding

Double-check Notepad++'s status bar at the bottom-right to confirm your selection.

Shebang #! unrecognized in Ubuntu, File created in Windows7 | Troubleshoot encoding

After saving and running from the command line, you should find that the PHP interpreter directive is now properly recognized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜