Shell scripts are compatible with linux/unix and windows/cygwin

Source: Internet
Author: User

Shell scripts are compatible with linux/unix and windows/cygwin, and are set on notepad: edit-> archive format conversion-> convert to UNIX format. In addition, I think it may be a good habit to display carriage returns and line breaks in my own editor, my "pain" experience (passed string parameters include \ r characters) reason: I need to run shell scripts under cygwin; in the script, the python subscript is called and parameters are passed at the same time. The script content is like this (the called python script prints the parameters passed to it) ========================================================== ======= #! /Bin/sh #====================================#funcion: # autor: luogw # date: 2013/6/27 # usage (in cygwin ):. /checkCompatibility checedFileName(.csv format) newFileName(.csv format, Added Compatibility problem) # comment 'rm-f temp4Compatibility.csv python. /cleanPath. py $1 $ tempFileNamepython. /checkNew. py temp4Compatibility.csv $2 filter.csv filter_key.cs Vrm-f $ tempFileName ==================================== ============== the running conditions are as follows: please pay attention to the value of tempFileName after it is passed to the python script! After \ r is added, let's take a look at the script windows document format and unix document format layout, and display the carriage return line break. notepad settings: view-> display characters-> display all characters in windows format (Script status when a problem occurs) unix format (OK status) My understanding: scripts running in cygwin/unix-like environments, if the shell script is saved in the windows document format (with carriage return and line break), the shell will append the string because the carriage return "\ r" is a common character in the unix environment. In addition, shell scripts in windows document format may appear when running in linux/unix :. /checkCompatibility. sh:/bin/sh ^ M: Bad Interpreter: There is no file or directory (solution is to remove the carriage return and transfer it to the unix document format) however, the cygwin environment can run normally, but it is quite a matter of love, but think about its own implementation is to provide a unix-like running environment in windows, it can handle shell scripts in windows document format, but it is not necessary to handle the issue that I encountered today.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.