Learn to parse file names correctly, and thereby ensure your scripts work as intended!

You would have to do all sorts of string modifications to make this work.

That is, unless you have the secret recipe.

Terminal window showing the manual page for the Mutt email client on Linux

Thelsoutput will contain hex codes which represent the color to use to your terminal.

To avoid running into these, simply use–color=neveras an option tols:

ls –color=never.

I have seen this issue as recent as mid August 2020 on Ubuntu.

Article image

What isNULLtermination you ask?

Consider how in the examples above,CR(or literallyenter) was the main termination character.

Disables the end of file string, which is treated like any other argument.

Setting up a file with a CR character in the filename

Useful when input items might contain white space, quote marks, or backslashes.

The GNU find -print0 option produces input suitable for this mode.

This option corresponds to the -0 option of xargs.

The problem trying to handle a filename which includes CR

TheTrue;here meansIf the option is specified, the following is true;.

-name ‘a*’ -print0

find .

-name ‘a*’ -print0 | xargs -0 ls

find .

Showing how xargs will see the CR character as a newline and split data upon it

-name ‘a*’ -print0 | xargs -0 rm

First we check our directory listing.

All our filenames containing special characters are there.

We next do a simplefind … -print0to see the output.

All sorts of special characters in filenames

We note that the strings areNULLterminated (with theNULLor- the same character - not visible).

We press enter at the$terminal prompt to make things a bit clearer.

Next we addxargswith the-0options, which enablesxargsto handle theNULLterminated input correctly.

The solution: find -print0 and xargs -0

Thermworks perfectly, and no errors or parsing issues are observed.

Increased security, and no issues with special characters.