iconv -l输出传递到管道时有所不同

问题描述

我发现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,似乎没有。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...