automated COL and WCOL settings

Thomas Beaudry k8la at arrl.net
Tue Jul 17 19:20:09 PDT 2001


> This $COLUMNS variable would be nice if we can guarantee that the
> variable is set in 100% of the times, no matter what. I'm sure the bash
> man page has some info when this var. may not be set. I'll read up on it
> and then decide on a course of action.

Well, it turns out the COLUMNS variable isn't set until the shell 
receives a SIGWINCH.  So here's what I came up with.  Not any easier but 
gets rid of the need for cut.  I'm not fond of using external commands in 
my startup scripts if it can be avoided.



# If COLUMNS hasn't been set yet, do it ourself
if [-z "$COLUMNS"] then

	# Get the console device if we don't have it already
	test -z "$CONSOLE" && CONSOLE=/dev/console

	# Get the console size (rows columns)
	SIZE=$(stty size < $CONSOLE)

	# Strip off the rows leaving the columns
	COLUMNS=${SIZE#*\ }
fi

COL=$[$COLUMNS - 10]
WCOL=$[$COLUMNS - 30]



BTW, I'm using this on my machine now.  Works great.  (And yes, I 
sacrificed my uptime to verify no boot time problems... <ggg>)
-- 
Unsubscribe: send email to lfs-discuss-request at linuxfromscratch.org
and put unsubscribe in the subject header of the message



More information about the lfs-dev mailing list