tr -d [=,=] 是做什么的?

What does tr -d [=,=] do?

我有一个代码示例,似乎在某些文本处理的末尾附加了一段额外的格式:

tr -d [=,=]

我不知道这有什么用,tr 的手册页帮不上什么忙。对此有何见解?

它只会删除 == 之间的逗号。检查下面的输出。

%_Host@User> echo "1==,==2==,==3=,=4=,=5" | tr -d [=,=]
1====2====3==4==5
%_Host@User>

谢谢。

来自 man tr 页面,

[=equiv=]

Equivalence classes

The syntax [=C=] expands to all of the characters that are equivalent to C, in no particular order. Equivalence classes are a relatively recent invention intended to support non-English alphabets. But there seems to be no standard way to define them or determine their contents. Therefore, they are not fully implemented in GNU tr; each character's equivalence class consists only of that character, which is of no particular use.

来自 POSIX tr 页面的示例

此示例使用等价 class 来识别文件 1 中基本字符 'e' 的重音变体,这些变体从 diacritical marks (WikiLink) 中剥离并写入文件 2。

tr "[=e=]" "[e*]" <file1 >file2

即如果在 file1 中,如果 e 表示为重音符号(éè),它们将被视为正常 e