[sf-lug] dpkg -l & COLUMNS, & shell and environment ...

Michael Paoli Michael.Paoli at cal.berkeley.edu
Wed Aug 2 07:18:25 PDT 2017


Something like this will be quite readable:
$ COLUMNS=$(tput cols) dpkg -l | less
Though I'll often do something like this:
$ COLUMNS=300 dpkg -l | ...
when I want to reasonably ensure none of the output columns are
truncated due to output width constraints.

> From: "Rick Moen" <rick at linuxmafia.com>
> Subject: Re: [sf-lug] NEED INFO ABOUT BOOT SECTOR, SPACE LIMITS
> Date: Tue, 1 Aug 2017 10:08:22 -0700

> Quoting Alex Kleider (akleider at sonic.net):
>
>> Yes, the output is very difficult to read and even with the widest
>> window possible on my laptop, all the lines ran over so I came up
>> with the following little script that might be of use to others.
>
> That's a nice little Python script.  But, are you sure you need it?,
> On every apt/dpkg-based system I've used, it's sufficient to just make
> sure your terminal is at least 80 columns wide, and then 'dkpg -l |
> less' displays quite legibly.
>
> If you want to force 'dpkg -l' to take terminal width into account, use
> local shell variable COLUMNS.  Otherwise, 'dpkg -l' will use column
> sizes based on the longest fields; thus the output may be wider than the
> terminal.
>
> COLUMNS=$COLUMNS dpkg -l | less

And, actually, just to point it out, in bash/POSIX/bourne/etc. shells,
if one does something like:
$ FOO=whatever some_command
That sets environment variable FOO to whatever for that invocation of
some_command, and without otherwise changing the shell's
environment.  One could, alternatively, use the env(1) command,
but by not using the env(1) command we save the overhead of an
entirely separate external command execution ... not to mention also
saving some keystrokes.
One can also set multiple environment variables at the same time:
$ TERM=linux-m EXINIT='se ...' vi ...
e.g. on a host where vi is vim (ugh), and I don't want no seenkin' colors.




More information about the sf-lug mailing list