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.重新启动并运行命令,发现正常启动,至此完毕。
    

      

  • 相关阅读:
    PCL利用RANSAC自行拟合分割平面
    HDU 3062 && HDU 1824 && POJ 3678 && BZOJ 1997 2-SAT
    BZOJ 3670 && BZOJ 3620 && BZOJ 3942 KMP
    BZOJ 1500 Splay 全操作
    Manacher
    POJ 2155 2维线段树 || 2维BIT
    BZOJ 1015 并查集+离线倒序
    NOI Linux JAVA
    UVA 10407 差分思想的运用
    BZOJ 1969 树链剖分+Tarjan缩点
  • 原文地址:https://www.cnblogs.com/liuhaidon/p/11871877.html
Copyright © 2011-2022 走看看