设为首页 收藏本站
查看: 1243|回复: 0

[经验分享] /usr/bin/perl^M bad interpreter No such file or directory

[复制链接]

尚未签到

发表于 2018-8-31 06:27:19 | 显示全部楼层 |阅读模式
  /usr/bin/perl^M: bad interpreter: No such file or directory
  今天执行 ./shuffleSequences.pl 遇到 /usr/bin/perl^M: bad interpreter: No such file问题,在网上找了找英文和中文的
  问题决。
  说法挺多。用vi shuffleSequences.pl 有的第一行是#!/usr/bin/perl -w时就出这个问题,改成#!/usr/bin/perl后就没问题的。我的第一行就是#!/usr/bin/perl,改成#!/usr/bin/perl -w,居然就没问题了。转 的文章 如下:
  http://emmune.appspot.com/2009/08/31/CtrlM.html
  /usr/bin/perl^M: bad interpreter: No such file or directory
  八月 31st, 2009
  前 段时间摆弄服务器,遇到很多问题。当时go2china8还能用,一一记下后越墙发到了狗窝随笔上。最近好像go2china8也和谐了,只好在这儿一面 之词了。最近遇到的这个问题,很奇怪。一个perl脚本,运行后返回/usr/bin/perl^M: bad interpreter: No such file or directory。网上查,说法挺多。有的第一行是#!/usr/bin/perl -w时就出这个问题,改成#!/usr/bin/perl后就没问题的。我的第一行就是#!/usr/bin/perl,改成#!/usr/bin /perl -w,居然就没问题了。奇了怪了。忽然想起3年前在日本使用的solaris9系统服务器时似乎也遇到了同样问题。翻出就日志一看,应该就是 windows与unix文本文件格式不同所致。现摘抄我的旧文如下。当时我用的居然是英文。
  Be aware that UNIX text file format is different from Windows system
  The UNIX and DOS operating systems (which includes Microsoft Windows) differ in the format in which they store text files. DOS places both a line feed and a carriage return character at the end of each line of a text file, but Unix uses only a line feed character. Some DOS applications need to see carriage return characters at the ends of lines, and may treat Unix-format files as giant single lines. Some Unix applications won't recognize the carriage returns added by DOS, and will display Ctrl-m characters at the end of each line. This appears on the screen as ^M.
  On systems using SunOS, the utilities dos2unix and unix2dos are available. These utilities provide a straightforward method for converting files from the Unix command line. To use either command, simply type the command followed by the name the file you wish to convert, and the name of a file which will contain the converted results. Thus, to convert a DOS file to a Unix file, at the Unix prompt, enter: dos2unix dosfile.txt unixfile.txt. To convert a Unix file to DOS, enter: unix2dos unixfile.txt dosfile.txt. Note that these utilities are only available on SunOS systems.
  To convert a DOS text file to a Unix text file using Perl, at the Unix shell prompt, enter: perl -p -e 's/\r$//' < dosfile.txt > unixfile.txt. To convert from a Unix text file to a DOS text file with Perl, at the Unix shell prompt, enter: perl -p -e 's/$/\r/' < unixfile.txt > dosfile.txt. Please note that you must use single quotation marks in either command line.  This prevents your shell from trying to evaluate anything inside.
  我 想linux是与时俱进的,于是在在bash中输入,which dos2unix,返回/usr/bin/dos2unix,同样unix2dos也有的。哈哈,看来these utilities are not only available on SunOS systems. 不过命令似乎更简单,只需要dos2unix dosfile,结果dosfile自动变成了了unix format的了。运行perl脚本,一切OK!
  因此,我的如下修改了:
  从windows的文件格式转换成linux下的文件格式:
  perl -p -e 's/\r$//' < dosfile.txt > unixfile.txt
  从linux的文件格式转换成windows下的文件格式:
  perl -p -e 's/$/\r/' < unixfile.txt > dosfile.txt
  OK!


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-559016-1-1.html 上篇帖子: 关于perl语句的注释方法 下篇帖子: perl脚本异常:bad interpreter No such file or directory
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表