PROPHET/OS

NAME

tr: replaces every character of from with the character of to that stands at the same place

SYNOPSIS

tr [-streng] <from> <to>
tr selbsttest

DESCRIPTION

Replaces every character of from with the character of to that stands at the same place. One character for one character, and nothing else: no sets, no ranges, no classes.

Escapes in both sets: \n, \t, \r, \\ and \NNN with up to three octal digits, so \050 is a bracket.

What it does better than the original

**Two sets of different length are an error.** A classic tr pads the second set with its last character, so tr abc xy turns c into y and says nothing about it. Here the two lengths have to match.

**A pair that never fired is said.** The commonest bug of a tr in a build is one that runs, ends with 0 and changes nothing, because the character it looks for is written differently than the script thinks. Every character of from that never came is a line on err, and -streng makes the exit 1.

**What it does not know it names.** A range (a-z), a class ([:digit:]), a trailing backslash and an octal escape above 255 are refused with the place in the set, instead of being read as if every character stood for itself.

tr selbsttest drives nine cases without a keyboard: the five shapes the build itself uses, one that changes nothing, and three sets that have to be refused.

EXAMPLE

$ tr --help
tr [-streng] <from> <to>
  replaces every character of from with the one of to at the same place
  escapes: \n \t \r \\ and \NNN octal
  -streng  a pair that never fired makes the exit 1
  selbsttest  drives its own nine cases