简体   繁体   English

/ bin / bash ^ M:错误的解释器:没有这样的文件或目录

[英]/bin/bash^M: bad interpreter: No such file or directory

I am facing /bin/bash^M: bad interpreter: No such file or directory issue and I have already got the solution for it from this stack flow answer 我正在面对/ bin / bash ^ M:错误的解释器:没有此类文件或目录问题,并且我已经从此堆栈流程答案中获得了解决方案

-bash: ./my_script: /bin/bash^M: bad interpreter: No such file or directory -bash:./my_script:/ bin / bash ^ M:错误的解释器:无此类文件或目录

which works fine. 效果很好。

My question is every time when I restart my ubuntu machine I have to redo everything That is I execute dos2unix -k -o filename every time I start my system. 我的问题是每次重新启动ubuntu机器时,我都必须重做所有操作。也就是说,每次启动系统时,我都执行dos2unix -k -o filename。

Is there any way this can be just once? 有什么办法可以只是一次吗?

Please note: I had to create a new question because I was not able to ask the question or comment in the existing question due to less reputation 请注意:我不得不创建一个新问题,因为由于声誉降低而无法提出该问题或在现有问题中发表评论

This is a very common problem of running a bash script from a file saved with Microsoft OS machine (a virtual machine maybe?) such as Windows or DOS. 这是一个非常普遍的问题,即从Microsoft Windows机器(例如,虚拟机?)保存的文件(例如Windows或DOS)中运行bash脚本。

So you know the fix to your problem. 因此,您知道解决问题的方法。

Now you should prevent your problem reoccurring every time you login. 现在,您应该避免每次登录时再次出现问题。 Identify how the file is generated/copied/damaged by another resource. 标识文件如何被其他资源生成/复制/损坏。 Like .bash_profile script or crontab script or any other management deamon. 类似于.bash_profile脚本或crontab脚本或任何其他管理守护进程。

The first line of your bash script should be the Shebang ( #!/bin/bash ). bash脚本的第一行应该是Shebang( #!/ bin / bash )。

I see the error says: /bin/bash But is should be changed to: #!/bin/bash 我看到错误提示: / bin / bash但应更改为: #!/ bin / bash

Then run: 然后运行:

$ dos2unix my_script

This will change all the line terminators from \\r\\n (Windows) to \\n (Linux), this will modify the original my_script file so it will persist even after a reboot. 这会将所有行终止符从\\ r \\ n (Windows)更改为\\ n (Linux),这将修改原始的my_script文件,因此即使重新启动后该文件也将保留。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Cron作业执行bash脚本时出现“ / bin / bash ^ M:错误的解释器:没有这样的文件或目录”错误 - “/bin/bash^M: bad interpreter: No such file or directory” error when executing a bash script from a cron job -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: 没有那个文件或目录 - -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory /usr/bin/ruby2.3:错误的解释器:没有这样的文件或目录 - /usr/bin/ruby2.3: bad interpreter: No such file or directory my_script抛出bash错误:/ home / usr / bin / my_sript:bin / bash /错误的解释器:没有这样的文件或目录。 我该如何纠正该错误? - my_script throwing an error of bash: /home/usr/bin/my_sript: bin/bash/ bad interpreter: No such file or directory. How can I correct this error? 运行Bash脚本会导致“错误解释器:无此类文件或目录”错误 - Running a Bash script results in 'Bad interpreter: No such file or directory' error Python / usr / bin / env:错误的解释器:不是目录 - Python /usr/bin/env: bad interpreter: Not a directory !#/ bin / bash:没有这样的文件或目录 - !#/bin/bash: No such file or directory / usr / local / bin / python3:错误的解释器:ubuntu 14.04没有这样的文件或目录 - /usr/local/bin/python3: bad interpreter: No such file or directory for ubuntu 14.04 运行 pipenv, mkdocs 时出错:/usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory - Error running pipenv, mkdocs : /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory “ /usr/bin/javac:/lib/ld-linux.so.2:错误的ELF解释器:没有这样的文件或目录” - “/usr/bin/javac: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM