zoukankan      html  css  js  c++  java
  • shell脚本兼容linux/unix与windows/cygwin的基础(注意处理好CR, LF, CR/LF 回车 换行的问题)

    shell脚本兼容linux/unix与windows/cygwin的基础 :统一文本格式为:unix文本格式,即于LF为换行符(推荐方案)
    在notepad上设置:编辑->档案格式转换->转换为UNIX格式
    另外我觉得在自己使用的编辑器上显示回车、换行符也许是个好的习惯吧
     
    有关于回车,换行的故事:转送门在这里,猛击吧!http://blog.sciencenet.cn/blog-948919-697160.html
     
    关于回车换行问题,我的”痛苦“经历(传递的字符串参数有 字符
     
    原由:我需要cygwin下运行shell 脚本;脚中调用python子脚本且同时传递参数
    我的脚本内容是这样的(调用的python脚本中会打印传递给他的参数)
    ===============================================
    #!/bin/sh
    # ============================
    # funcion:
    # autor:luogw
    # date:2013/6/27
    # usage(in cygwin): ./checkCompatibility checedFileName(.csv format) newFileName(.csv format,Added Compatibility problem)
    # ============================
    tempFileName='temp4Compatibility.csv'
    rm -f temp4Compatibility.csv
    python ./cleanPath.py $1 $tempFileName
    python ./checkNew.py temp4Compatibility.csv $2 filter.csv filter_key.csv
    rm -f $tempFileName
    ================================================
    运行情况如下:大家请注意 tempFileName的值,传给python脚后!添加了

     
    我们先看看脚本windows文档格式与unix文档格式载图,显示回车换行符;notepad的设置 : 视图->显示字符->显示所有字符
     
    windows格式(出问题时脚本的状态)

    unix格式(ok的状态)

     
    个人理解:
    在cygwin/类unix环境下运行的脚本,如果shell脚本是于windows文档格式保存的(有回车,换行符)
    因为unix环境下shell会把回车符" "当普通的字符处理,故会造成字符串追加。

     
     
     
    另外windows文档格式的shell脚本,在linux/unix环境下运行时是会出现:bash: ./checkCompatibility.sh: /bin/sh^M: 坏的解释器: 没有那个文件或目录 (解决方案就是去掉回车了,转给unix文档格式)
    但是cygwin环境下是可以正常运行的,很变恋吧,但想想它本身实现就是在windows下提供类unix的运行环境,它能处理windows文档格式的shell脚本也是不可厚非的事
    只是得需要注意我今天所遇到的问题


  • 相关阅读:
    OM Shipping 授权
    Account Summary 汇总模板
    OM Record is currently being worked on by another user, Please try to update it later.
    Initialization SQL Statement – Custom 配置错误,导致无法加载FORM
    ReOpen a Closed Inventory Accounting Period [ID 472631.1]
    IBM AIX User Lists
    Killing Oracle Sessions
    APPFND01016 (GL > Setup > Flexfields > Key > Rules)
    OM: release hold的时候,又遇到限制:You are not authorized to release this hold.
    SO History
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3174553.html
Copyright © 2011-2022 走看看