Modify line breaks for Windows files

Source: Internet
Author: User

Application Scenarios:

In the office, it is possible that some command scripts are written using a text editor under Windows to run an error when put into Linux in the test environment

Software to use: Xxd hexdump Dos2unix

1. Run a well-written SH script on Windows

[[email protected] ~]# Bash Test.shtest.sh:line 2: $ ' \ R ': Command not found ' f:invalid option--' Try ' df--help ' for mor E information.test.sh:line 4: $ ' \ R ': Command not found ' s:invalid option--' Try ' ls--help ' for more information.test.sh : Line 6: $ ' \ R ': Command not Found

2. View SH script

[email protected] ~]# cat Test.sh#!/bin/bashdf-hls-l
  

3. View the binary of the text

[Email protected] ~]# xxd test.sh 0000000:2321 2f62 696e 2f62 6173 680d 0a0d 0a64  #!/bin/bash....d0000010:6620 2d68 0d0a 0d0a 6c73 202d 6c0d 0a0d  f-h....ls-l ... 0000020:0a                                       .

4. View the hexadecimal text

[[email protected] ~]# hexdump test.sh0000000 2123 622f 6e69 622f 7361 0d68 0d0a 640a0000010 2066 682d 0a0d 0a0d 736c 2d20 0d6c 0d0a0000020 000a                                   0000021

5. Use Dos2unix to modify text

Note: Dos2unix needs to be installed, the default system is not installed

[Email protected] ~]# Dos2unix test.shdos2unix:converting file test.sh to Unix format ...

6. View the binary and hexadecimal of modified files

# binary [[email protected] ~]# xxd test.sh 0000000:2321 2f62 696e 2f62 6173 680a 0a64 6620  #!/bin/bash. DF 0000010:2d68 0a0a 6c73 202d 6c0a 0a              -H. Ls-l. # hex 0000000 2123 622f 6e69 622f 7361 0a68 640a 20660000010 682d 0a0a 736c 2d20 0a6c 000a          000001b

7. Contrast

Windows: Binary line break symbol: 0d0alinxu: Binary line break symbol: 0a

Modify line breaks for Windows files

Related Article

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.