zoukankan      html  css  js  c++  java
  • linux使用windows中编辑的文件,格式问题

    参考:https://blog.csdn.net/yongan1006/article/details/8142527

    运行脚本时出现了这样一个错误,打开之后并没有找到所谓的^M,查了之后才知道原来是文件格式的问题,也就是linux和windows之间的不完全兼容。。。
    具体细节不管,如果验证:

    vim test.sh
    :set ff?
    如果出现fileforma=dos那么就基本可以确定是这个问题了。
    :set fileformat=unix
    :wq

    OK了。。。。。。。

    bash: ./eth0-access: /bin/bash^M: bad interpreter: 没有那个文件或目录

    错误分析:

    因为操作系统是windows,我在windows下编辑的脚本,所以有可能有不可见字符。

    脚本文件是DOS格式的, 即每一行的行尾以 来标识, 其ASCII码分别是0x0D, 0x0A.

    可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MAC格式的

    解决方法:

    vim filename

    然后用命令

    :set ff? #可以看到dos或unix的字样. 如果的确是dos格式的。

    然后用

    :set ff=unix #把它强制为unix格式的, 然后存盘退出。

    再次运行脚本。

  • 相关阅读:
    背水一战 Windows 10 (90)
    背水一战 Windows 10 (89)
    背水一战 Windows 10 (88)
    背水一战 Windows 10 (87)
    背水一战 Windows 10 (86)
    背水一战 Windows 10 (85)
    背水一战 Windows 10 (84)
    背水一战 Windows 10 (83)
    背水一战 Windows 10 (82)
    背水一战 Windows 10 (81)
  • 原文地址:https://www.cnblogs.com/vactor/p/9037995.html
Copyright © 2011-2022 走看看