getting column width in various shells

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Wed Nov 8 20:06:23 UTC 2006


On Wed, Nov 08, 2006 at 07:57:14AM -0500, Madison Kelly wrote:
> Hi all,
> 
>   I am trying to add line-wrapping to my program and to this end I am 
> trying to figure out the different ways of getting the current number of 
> columns from the different shells. I am hoping you guys who use shells 
> other than bash or sh might be able to help me build a list.
> 
> For 'bash' and 'sh', I know this works:
> $ echo $COLUMNS
> 
> For 'csh' and 'tsch', I *thought* it was the same, and the man page 
> seems to agree, but I only get an error:
> 
> > echo $COLUMNS
> COLUMNS: Undefined variable.
> 
> Beyond these four, I am not even really sure what shells are in common 
> use, so feedback on that would be helpful, too.

Don't ask the shell.  It has no clue.  You ask the terminal.  That is
why most programs that care about placement of things on the screen use
curses to handle talking to different terminal types.  As someone
suggested, tput may help, since it is a curses based utility for asking
the terminal that kind of thing.

Of course it may change while your program is running, which is
something else curses supports dealing with on the fly.

--
Len Sorensen
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list