Skip to content
Advertisement

Linux tr command not working as expected

I have this password generator:

JavaScript

Which works fine as follows:

JavaScript

But fails as follows:

JavaScript

The tr command is explicitly saying:

remove all characters which do not belong to the given set

Thus the characters , and . are unexpected.

Where do they come from?

Advertisement

Answer

There’s also another part of tr‘s man page that you overlooked:

CHAR1-CHAR2

all characters from CHAR1 to CHAR2 in ascending order

So the part +-/ will mean the characters +, ,, -, . and /. (man ascii is useful here).

For a hyphen you can escape it:

JavaScript

use 55 instead:

JavaScript

or put it at the end:

JavaScript
Advertisement