Subject: bug#20474: tr command

From: Eric Blake <[email-masked]>
Date: Thu, 30 Apr 2015 11:10:52 -0600

On 04/30/2015 10:31 AM, Joseph Piette wrote:
> Hello:
> 
> When transferring files from the Windows environment to the Linux environment we execute a script to remove the \cr characters. The script performs a simple
> 
> tr -d '\r'  < input  > output
> 
> Recently we were testing with files that contained a string with a single quote - "Paym't"
> 
> What the tr command is doing is not only removing the "\cr" characters but also the single quote. What we ended up with was "Paymt"

It looks like correct usage if you are using a POSIX shell.  But you
didn't specify if that was the case. Are you running the script on
Windows, using 'cmd' to drive a pre-built version of tr for Windows?  If
so, it is very likely that the unusual quoting rules for cmd (very
different from POSIX shell) are the cause for your problem.  That is,
the command line being constructed may be something like 'tr -d "'\\r'"
...', where you are unintentionally passing literal ' on to tr, and tr
is then faithfully deleting single quotes.  If you are indeed running tr
on Windows, try:

echo tr -d '\r'

to see if the cmd shell is getting in the way.  Or move your files to
Linux, and run tr on Linux rather than on Windows, to ensure that you
are not being bitten by Windows oddities.

Another thing to try: the 'dos2unix' command exists in many Linux
distros as a way to automate the work without having to figure out the
commands to run yourself.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org