-bash:./my_script:/斌/ bash的^ M:不好间preTER:没有这样的文件或目录 [英] -bash: ./my_script: /bin/bash^M: bad interpreter: No such file or directory

查看:135
本文介绍了-bash:./my_script:/斌/ bash的^ M:不好间preTER:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学完本教程学习的bash脚本为我自动完成一些任务。我使用腻子连接到服务器。

该脚本,位于 ... /文件/ LOG 是:

 #!/斌/庆典
#我的第一个脚本
回声的Hello World!

和我执行的读/写以下/执行权限

 行chmod 755 my_script

然后,当我进入 ./ my_script ,我得到的标题给出的错误。

一些类似的问题想看到这些,所以我认为他们可能会有所帮助:

 这庆典


  

/斌/ bash的


 回声$ PATH


  

在/ usr / local / sbin中:在/ usr / local / bin目录:/ usr / sbin目录:在/ usr / bin中:/ sbin目录:/ bin中:在/ usr /游戏:在/ usr / bin中/ MH


我尝试添加当前目录 PATH ,但不起作用。


解决方案

我已经在Windows中创建ENV脚本时,然后移植到在UNIX环境中运行见过这个问题。

尝试在脚本运行这样的:

  http://linuxcommand.org/man_pages/dos2unix1.html

或使用和测试只是重写剧本在您的UNIX ENV。

UNIX使用不同的线路和回车,因此无法读取您在Windows创建的文件。因此,它是看到^ M作为非法字符。

如果您想通过写Windows中的文件,然后端口,请确保您的编辑器设在UNIX格式创建的文件。

在屏幕右下角的记事本+ +它告诉你的文档格式。默认情况下,它会说 DOS \\的Windows 。要想改变它转到


  • 设置 - > preferences

  • 新的文件/ default目录标签

  • 选择格式,UNIX和关闭

  • 创建一个新的文件

I'm learning through this tutorial to learn bash scripts to automate a few tasks for me. I'm connecting to a server using putty.

The script, located in .../Documents/LOG, is:

#!/bin/bash
# My first script
echo "Hello World!"

And I executed the following for read/write/execute permissions

chmod 755 my_script

Then, when I enter ./my_script, I'm getting the error given in the title.

Some similar questions wanted to see these, so I think they might help:

which bash

/bin/bash

and

echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/bin/mh

I tried adding current directory to PATH, but that doesn't work..

解决方案

I have seen this issue when creating scripts in Windows env and then porting over to run on a unix environment.

Try running this on the script:

http://linuxcommand.org/man_pages/dos2unix1.html

Or just rewrite the script in your unix env using vi and test.

Unix uses different line feeds and carriage returns so can't read the file you created on Windows. Hence it is seeing ^M as an illegal character.

If you want to write a file on Windows and then port over, make sure your editor is set to create files in UNIX format.

In notepad++ in the bottom right of the screen it tells you the document format. By default it will say Dos\Windows. To change it go to

  • settings->preferences
  • new document / default directory tab
  • select the format as unix and close
  • create a new document

这篇关于-bash:./my_script:/斌/ bash的^ M:不好间preTER:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆