linux命令将doc转换为linux

shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory

 

  1. #!/bin/sh  
  2.   
  3. echo "test shell "  

具体报错信息以下:html

  1. [root@localhost test]# ./test.sh   
  2. -bash: ./test.sh: /bin/sh^M: bad interpreter: No such file or directory  

主要缘由是test.sh是在windows下编辑而后上传到linux系统里执行的。.sh文件的格式为dos格式。而linux只能执行格式为unix格式的脚本。linux

能够经过vi编辑器来查看文件的format格式。步骤以下:shell

1.首先用vi命令打开文件windows

  1. [root@localhost test]# vi test.sh   

2.在vi命令模式中使用 :set ff 命令bash

能够看到改文件的格式为dos编辑器

3.修改文件format为unixpost

方法一:使用vi修改文件formatspa

命令:set ff=unixunix

执行完后再经过set ff命令查看文件格式,结果以下:orm

方法二:直接使用dos2unix命令修改

  1. [root@localhost test]# dos2unix test.sh   
  2. dos2unix: converting file test.sh to UNIX format ...  

 修改完后再次执行./test.sh,执行正确:

  1. [root@localhost test]# ./test.sh   
  2. test shell
相关文章
相关标签/搜索