Question

On a fresh WordPress install in Linux distributions, wp-config-sample.php contains Carriage Return control characters that are not found in any other .php file in the distribution.

Running

egrep -l $'\r'\$ *.php

in WP's base dir, will return only wp-config-sample.php


I am not worried about eliminating the control character, nor am I worried that it interferes with install operations (it doesn’t).

I’d just like to find out if there’s a reason why wp-config-sample.php is the only file with this anomaly.


WP versions
Issue was reported in version 4.6.15. It is still present in the latest version 5.5

Environments
This behavior has been seen in

  • Debian 10 CLI-only
  • Ubuntu 18.04.4 LTS
  • Ubuntu 12.04.5 LTS
  • Ubuntu 20.04.1 LTS

WordPress distributions
Install files have been downloaded either

  • as .zip file (e.g. wordpress-5.5.zip) or
  • as .tar.gz file (e.g. wordpress-5.5.tar.gz)

Downloads methods

  • via wget: wget https://wordpress.org/latest.zip
  • via WP CLI: wp core download
  • via a Web browser (in GUI environments)

Example screenshot from Ubuntu 12.04.5 LTS

Ubuntu 12.04.5 tar.gz version


A Google search doesn't provide any explanation. I have found only a similar question in the WP support forum but the reply given is "don't worry about it" and does not provide an explanation for it.

Was it helpful?

Solution 2

From Wordpress support:

It’s for formatting on legacy DOS based systems. Some DOS and Windows based editors will not handle the file correctly without those additional ^M carriage return character. A UNIX based system will work with or without them and that’s why they don’t matter.

https://en.wikipedia.org/wiki/Newline

This is how a portion of that file should edit.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Which is readable.

If a new user used the Windows notepad editor then the file would may look like this especially on older versions of Windows.

// ** MySQL settings - You can get this info from your web host ** ///** The name of the database for WordPress */define( 'DB_NAME', 'database_name_here' );/** MySQL database username */define( 'DB_USER', 'username_here' );/** MySQL database password */define( 'DB_PASSWORD', 'password_here' );/** MySQL hostname */define( 'DB_HOST', 'localhost' );

Which is one line of mess. It would still work as a PHP file because the newline is less important than the ; in the file. The additional ^Ms will be ignored and for those other editor applications the user will see something they can both parse and edit.

OTHER TIPS

Unix and Unix-like operating systems (like Linux) use different line endings in their text files.

The format of Windows and Unix text files differs slightly. In Windows, lines end with both the line feed and carriage return ASCII characters, but Unix uses only a line feed. As a consequence, some Windows applications will not show the line breaks in Unix-format files. Likewise, Unix programs may display the carriage returns in Windows text files with Ctrl-m (^M) characters at the end of each line.

—From Convert between Unix and Windows text files

Presumably you've copied a file that was created on Windows to a Linux machine, and so you're seeing the Windows line endings when you edit the file on Linux.

The solution provided in your wordpress.org support post -- use dos2unix -- will clean it up.

I can't say precisely why your question was downvoted, as I'm not the downvoter, but if I had to guess I'd say it was because this is a Windows / Linux question, not a specifically WordPress-related question. (Yes, it's a WordPress file, but it's not really related to WordPress development at all.)

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top