bug-textutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is this a bug in tr?


From: Godwin Stewart
Subject: Is this a bug in tr?
Date: Sun, 28 Oct 2001 11:14:34 +0100

Hi,

I wanted a shell script to convert all the filenames in a given directory so
that any uppercase letters are made lowercase and so that any spaces are
replaced by an underscore.

Great, I thought. This is just what tr was made for. Then I had a
surprise...

This is the script itself, with most of the "works" commented out while I
was trying to narrow down the source of the problem I was having:

#!/bin/bash
#
#
# Script to convert all filenames to lower case, and to replace spaces with
underscores
#
#

ls | while read f; do
  g=`echo "$f" | tr A-Z a-z | tr [:blank:] _`
  echo "$f --> $g"
#  if [ "$f" != "$g" ]; then
#    avoid overwriting a pre-existent file:
#    while [ -e "$g" ]; do
#      g="_${g}"
#    done
#    mv "$f" $g
#    echo "\"$f\" renamed to \"$g\""
#  fi
done

As you can see, all this does is perform the conversion and display the old
filename alongside the new filename. Both will be the same if no conversion
took place in the echo | tr | tr pipeline.

Now look at the output from my ~/bin directory:

<snipped for brevity>
genpage --> ge_page
genpage.c --> ge_page.c
mkconf --> mkco_f
n --> _
newpage --> _ewpage
nsconf --> _sco_f
onetel --> o_etel
showconf --> showco_f
unbase64 --> u_base64
unbase64.c --> u_base64.c
unstuff --> u_stuff

All the "n"s have been converted to underscores!!!

If I now do the same thing in another directory this doesn't happen and my
script's output is as expected.

I have narrowed the origin of the problem down to the "tr [:blank:] _" bit.
So, it would appear that tr considers the "n" character to be a whitespace
if $PWD is $HOME/bin.

As Alice said to herself, "it's getting curiouser and curiouser..."

I'm using RH 7.1 with a 2.4.10 kernel and version 2.0.11 of GNU textutils.

Message copied to address@hidden

-- 
 ____________________________________________
| G. Stewart   --   address@hidden |
| Port de Pontille, FR-37500 CHINON, FRANCE. |
 ____________________________________________
The day Microsoft make something that doesn't suck will
probably be the day they start making vacuum cleaners.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]