Our development environment generally uses the Windows operating system, while the test environment and the online environment generally use Linux. When you edit a shell script under Windows, an error occurs under Upload to Windows. There are two situations:
1, BOM head problem, the previous introduction, no longer continue
2, carriage return problem. Mainly in the Windows operating system, the use of the editor (Windows comes with a text editor or Zend Studio) to edit the shell script, in the process of line breaks, usually attach a carriage return, run in the Linux environment, the return character will affect the script to run, Returns a syntax error.
Let's take a look.
First, we edit a text (test00.php) under Windows, enter the following, then upload to the Linux server
We open it with VI and look, there seems to be no problem
We then write a file (test11.php) directly on the Linux server and enter the same content. But in contrast, we can clearly see that the size of the two files is not the same
1 root root : test00.php1 Root Root About + : test11.php
Use XXD to look at the coding situation and make a comparison:
Windows under |
Linux under |
0000000:6974 2069 7320 6120 7465 7374210d 0a69 It is a test!.. I0000010:7420 6973 2061 2074 6573 74210d0a6974T is a test!.. It0000020:2069 7320 6120 7465 7374210d 0a697420is a test!.. It0000030:6973 2061 2074 6573 7421is a test! |
0000000:6974 2069 7320 6120 7465 7374210a6974It is a test!. It0000010:2069 7320 6120 7465 7374210a6974 2069is a test!. It i0000020:7320 6120 7465 7374210a6974 2069 7320S a test!. It is0000030:6120 7465 7374210A a test!. |
We clearly see that after the files that are edited in Windows are uploaded to the Linux server, a carriage return (0d) is present in front (0a) of each line break.
So how do we solve this problem?
Many methods can be resolved using the Dos2unix filename command
[email protected] test]# Dos2unix test00.php dos2unix:convertingfiletest00.php to UNIX format ... [Email protected] test]# xxd test00.php0000000:6974 2069 7320 6120 7465 7374210a6974It is a test!. It0000010:2069 7320 6120 7465 7374210a6974 2069is a test!. It i0000020:7320 6120 7465 7374210a6974 2069 7320S a test!. It is0000030:6120 7465 7374 +A test![email protected] test]#
A carriage return issue for Windows edit Text and Unix edit text