tr [a-z] [A-Z] shows error in unix

ramesh picture ramesh · Feb 1, 2013 · Viewed 12.8k times · Source

In unix, the line echo "abc" | tr [a-z] [A-Z] shows following error:

    tr: extra operand `b'
    Try tr --help' for more information.

It does not show error and prints the correct output ABC if it is run from any other directory in the same server or in any other server. Inside a particular directory it shows the above error.
I verified and found no such conflicting file or script. No script exists having the name tr.
which tr command inside the directory as well as outside the directory gives the same output /usr/bin/tr.
In the place of tr, I even tried as echo "abc" | /usr/bin/tr [a-z] [A-Z] to avoid any confliction with other files, if any. But the same error persists.
And if I try echo "abc" | tr 'a' 'B', it produces the output as Bbc. I am not able to figure out the error.

Answer

Anton Kovalenko picture Anton Kovalenko · Feb 1, 2013

tr doesn't need brackets:

tr a-z A-Z

[a-z] have special meaning for your shell (expanded to a list of matching file name). There is probably a matching file (or several matching files) in a directory where it does not work.