问题描述
我发现Linux上的iconv -l
输出通过管道传递时有所不同。
$ iconv -l
The following list contain all the coded character sets known. This does
not necessarily mean that all combinations of these names can be used for
the FROM and TO command line parameters. One coded character set can be
listed with several different names (aliases).
437,500,500V1,850,851,852,855,856,857,858,860,861,862,863,864,865,866,866NAV,869,874,904,1026,1046,1047,8859_1,8859_2,8859_3,8859_4,8859_5,8859_6,8859_7,8859_8,8859_9,10646-1:1993,...
和
$ iconv -l | cat
437//
500//
500V1//
...
iconv --version
给出:
$ iconv --version
iconv (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation,Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.
为什么会这样?该差异记录在哪里? man iconv
没有提到这种区别。
解决方法
这是许多程序的典型行为。正如用户“ rowboat”所提到的,某些程序通过使用isatty
函数来检查输出是否为终端。
此行为的另一个示例是ls
命令,该命令将在文件夹中为每个文件输出一行,而不是为终端列出该行:
$ ls
a.out b.out c.out
$ ls | cat
a.out
b.out
c.out
对于ls
,此行为记录在手册页中,但对于iconv
,似乎没有。