[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: dpkg -l needs wider package name output



On Sun, Apr 13, 2003 at 10:41:38PM -0400, Travis Crump wrote:
> Colin Watson wrote:
> >On Sun, Apr 13, 2003 at 08:04:20PM -0400, Travis Crump wrote:
> >>Colin Watson wrote:
> >>>Set COLUMNS to something large, or use dpkg-query with the --showformat
> >>>option (check its man page).
> >>
> >>pretzalz@Pretzalz:~$ echo $COLUMNS
> >>145
> >>pretzalz@Pretzalz:~$ dpkg -l
> >><nice wide output>
> >>pretzalz@Pretzalz:~$ dpkg -l | less
> >><output squished into 80 columns>
> >>pretzalz@Pretzalz:~$ COLUMNS=145 dpkg -l | less
> >><nice wide output>
> >>
> >>Do you really have to specify COLUMNS every time when using dpkg/less? 
> >
> >'export COLUMNS'
> 
> Okay just for my own edification since I am still mildly confused.  I 
> know that I need to export a shell variable that I manually set if I 
> want it to be inherited by a subshell, but I never considered that I 
> would also have to export shell variables that were set for me.  So I 
> export COLUMNS, what exactly am I exporting?  It seems like I am 
> exporting a pointer to COLUMNS since if I resize the terminal, the new 
> value of COLUMNS is correctly picked up.  But at the same time, if I 
> start a new terminal from the terminal where I exported COLUMNS, COLUMNS 
> is still exported, but the new terminal's COLUMNS' value is independent 
> of the old terminal's and it works properly, which isn't consistent with 
> the idea that I am exporting a pointer.

You're making it far too complicated. :) By default variables are just
shell variables, private to the shell in which they're set. If you
export them, then they're copied into the environment of any future
subprocesses with whatever their current value might be at that future
time. The export builtin just sets a flag on the variable telling the
shell to copy it for future subprocesses; it doesn't have to worry about
whether it's "exporting a pointer" or not, since it's not actually
exporting it immediately.

> Also, I don't completely understand why 'dpkg -l | less' counts as a 
> subshell, but 'dpkg -l' doesn't.

That's not true. What's actually happening is that, if COLUMNS isn't
set, dpkg looks at its stdout to see whether it's a terminal, and if it
is it tries to automatically detect the terminal size. When you pipe
dpkg's output to less stdout is not a terminal so the autodetection
fails.

In my own code I prefer to look at stdin rather than stdout to avoid
this issue.

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: