On Sat, May 05, 2007, Avraham Rosenberg wrote about "bidiv and the default 
$COLUMNS value":
> After rereading the man page for bidiv, I cheched: echo $COLUMNS.
> As suspected, I got an odd number: 99.
> 
> Question: Where is this value defined ?

I completely missed this question (which has nothing to do with bidiv).

So here is a brief history of COLUMNS...

COLUMNS is a variable set by your shell (zsh, bash, tcsh, or whatever you're
using). The idea is that your shell knows what is the width of your terminal
and passes this knowledge to the programs it runs; A few of the familiar
Unix programs use this knowledge - for example "ls" by default shows the file
listing in multile columns, up to the terminal's width. As you saw, bidiv
also uses this variable.

In the "old days", terminals used to have fixed widths; If you had a vt100
terminal (TERM=vt100), then the width was always 80. If you had a AT&T 5620
terminal, the width was 88, and so on, and the "termcap" or "terminfo"
libraries was used to get this information based on the terminal name.
However, when resisable windows appeared in Unix (on the aforementioned 5620,
and in X-Windows), this fixed width was no longer enough, and the terminal's
(or actually, terminal emulator window's) width could be changed at any
moment.

This is when three new facilities were added to Unix. First, a window
width/hight setting was added to the tty (the "tty" is the Unix mechanism for
a terminal emulator to connect to a process, usually a shell, running in it).
See "stty -a" (and the TIOCSWINSZ ioctl). This was almost enough - your shell
and the processes it runs can now figure out at any moment what's the window's
current size. But should the shell (which needs to know the terminal's width,
e.g., for command line editing) try this ioctl on every command? Instead of
forcing it to check every time, a new signal was invented - SIGWINCH, "window
change". When the terminal emulator is resized, it sends its child process
(namely, your shell) a SIGWINCH signal. The shell then uses the ioctl to get
its current window size, and remembers it. The third mechanism is a shell
variable, COLUMNS, which gets updated when the shell learns of a new window
width. This feature is useful because ioctl's are "nonstandard" or "complex"
and using variables is easier; it also allows the user to easily override
the width; And it also works with pipes and redirections.

-- 
Nadav Har'El                        |       Sunday, May  6 2007, 18 Iyyar 5767
[EMAIL PROTECTED]             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |I have a great signature, but it won't
http://nadav.harel.org.il           |fit at the end of this message -- Fermat

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to