[Top][All Lists]

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

bug#24054: tr bug? [:space:] acts like "a"

From: Assaf Gordon
Subject: bug#24054: tr bug? [:space:] acts like "a"
Date: Fri, 22 Jul 2016 17:18:27 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

tag 24054 notabug
close 24045


On 07/22/2016 02:58 PM, address@hidden wrote:
For the last few weeks tr [:space:] isn't working the way it used to for me under Ubuntu 
14.04. Instead of acting on spaces it acts on "a"s.:

address@hidden:~$ echo "thisstring abcde what the heck?" | tr [:space:] '_'
thisstring _bcde wh_t the heck?

This is 64 bit 14.04 built up from the mini.iso with just plain Openbox as the 
only DE, in lxterminal using bash.

This is not a bug, but a result of your shell (bash) performing filename 
completion on single-letter filenames in your current directory.

In bash, the syntax [X] without quotes does filename completion, just like "*" or 

I would guess that in the last few weeks you created a file called 'a' in the 
and so '[:space:]' matched it  (technically it means: match filenames of one 
character, one of :,s,p,a,c or e).

It used to "just work", because if the shell does not find matching files, it 
passes the parameter as-is to the program.

The following will demonstrate:

    $ mkdir empty
    $ cd empty

    $ echo [:space:]

    $ touch a

    $ echo [:space:]

    $ touch ':'

    $ echo [:space:]
    : a

    $ echo '[:space:]'

Since the shell replaced '[:space:]' with 'a', the 'tr' command became:

    tr a '_'

which is the behavior you encountered.

The solution is to always quote such parameters:

    $ echo "thisstring abcde what the heck?" | tr '[:space:]' '_'

(The last underscore is the newline, which also counts as whitespace).

To learn more about bash's filename expansion capabilities, see here:

As such I'm closing this bug report, but discussion can continue by replying to 
this thread.

 - assaf

reply via email to

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