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

2016-07-22 Thread Assaf Gordon

tag 24054 notabug
close 24045
stop

Hello,

On 07/22/2016 02:58 PM, p...@tutanota.de 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.:

me@U:~$ 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 
directory,
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:]
[:space:]

$ touch a

$ echo [:space:]
a

$ touch ':'

$ echo [:space:]
: a

$ echo '[:space:]'
[: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:]' '_'
thisstring_abcde_what_the_heck?_

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

To learn more about bash's filename expansion capabilities, see here:
  https://www.gnu.org/software/bash/manual/bashref.html#Filename-Expansion


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

regards,
 - assaf






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

2016-07-22 Thread pmun
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.:

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

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



--
Securely sent with Tutanota. Claim your encrypted mailbox today!
https://tutanota.com