Redirection operator is limiting columns

夙愿已清 提交于 2019-12-24 01:18:30

问题


I am running the following command to list the packages installed on a server.

$> dpkg -l

This is fine but when I do this

$> dpkg -l > list_of_packages_installed

I only get 106 columns of data and the rest is cut off. So all the rows are there but not all the data column-wise. There must be something simple I am missing here?


回答1:


The variable COLUMN is indeed responsible for this. The manpage of dpkg(8) contains under the section "ENVIRONMENT":

   COLUMNS
         Sets  the number of columns dpkg should use when display-
         ing formatted text. Currently only used by -l.

if COLUMNS is set in your environment then dpkg will use it. You can check with this command:

env | grep ^COLUMNS=

if that command outputs something like

COLUMNS=80

then you know that this variable is set in your environment. Note that this command:

echo $COLUMNS

does not tell you if it is an environment or a shell variable. COLUMNS can be set as a shell variable without being exported to the environment. With this command:

COLUMNS=$COLUMNS dpkg -l > k

you explicitely put the variable in the environment of dpkg. If it was not in your environment then it will be for this command only. Also note that the behaviour of dpkg in this respect is different between ubuntu and debian and also depends on the version. There have been a few bug reports on this topic. The dpkg in squeeze for example will set the column width so that all package names and version can be displayed in full if COLUMNS is not set in the environment and the output is not a tty.

Regards



来源:https://stackoverflow.com/questions/7648718/redirection-operator-is-limiting-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!