zoukankan      html  css  js  c++  java
  • Shell—常见报错问题

    bash:$' ': command not found

    造成这个问题的原因是Windows环境下换行的“ ”到了Linux环境下不能够识别了,因为Linux环境下默认的换行符为“ ”,我们只需要把文件转成unix就好。使用 dos2unix 工具实现该转换。

    # 1.安装 dos2unix 工具
    [root@localhost ~]# apt install dos2unix         # Ubuntu系统
    [root@localhost ~]# yum -y install dos2unix   # Centos系统
    
    # 2.转换文件
    [root@localhost ~]# chmod 755 test.sh
    [root@localhost ~]# dos2unix test.sh
    
    # 3.再次执行文件就可以啦
    [root@localhost ~]# sh ./test.sh
    

    执行shell报bad interpreter: No such file or directory错误

    原因:.sh脚本在windows系统下编写的,所以可能有不可见字符,从上图错误提示来看,很有可能脚本文件是DOS格式的,即每一行的行尾以 来标识, 其ASCII码分别是0x0D, 0x0A。

    1.通过vim filename 或者vi filename 进入编辑,
    
    2.然后通过shift+:进入命令模式。接着通过命令set ff 或者 set fileformat 查看文件格式,这里显示的是fileformat=dos。
    
    3.修改文件格式dos为unix。通过命令set ff=unix 或 set fileformat=unix修改,然后再执行set ff 或者 set fileformat,查看是否修改成功。
    
    4.重新启动并运行命令,发现正常启动,至此完毕。
    

      

  • 相关阅读:
    事后诸葛亮
    OVS常用命令
    阿里云部署杂记
    Alpha冲刺总结
    测试随笔
    Alpha冲刺集合
    项目Alpha冲刺Day12
    项目Alpha冲刺Day11
    项目Alpha冲刺Day10
    MySQL修改密码
  • 原文地址:https://www.cnblogs.com/liuhaidon/p/11871877.html
Copyright © 2011-2022 走看看