<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: get the width of the terminal</title>
	<atom:link href="http://nixshell.wordpress.com/2009/09/08/get-the-width-of-the-terminal/feed/" rel="self" type="application/rss+xml" />
	<link>http://nixshell.wordpress.com/2009/09/08/get-the-width-of-the-terminal/</link>
	<description>UNIX / Linux Shell Hints and Tips&#160;&#160;&#160;&#160;&#160;&#160;(a http://steve-parker.org/sh/sh.shtml subproject)</description>
	<lastBuildDate>Sun, 31 Mar 2013 18:54:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: unixshell</title>
		<link>http://nixshell.wordpress.com/2009/09/08/get-the-width-of-the-terminal/#comment-5302</link>
		<dc:creator><![CDATA[unixshell]]></dc:creator>
		<pubDate>Thu, 22 Apr 2010 18:39:09 +0000</pubDate>
		<guid isPermaLink="false">http://nixshell.wordpress.com/?p=112#comment-5302</guid>
		<description><![CDATA[Thanks Jon for such a complete and clear post.]]></description>
		<content:encoded><![CDATA[<p>Thanks Jon for such a complete and clear post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Disnard</title>
		<link>http://nixshell.wordpress.com/2009/09/08/get-the-width-of-the-terminal/#comment-5301</link>
		<dc:creator><![CDATA[Jon Disnard]]></dc:creator>
		<pubDate>Thu, 22 Apr 2010 18:22:29 +0000</pubDate>
		<guid isPermaLink="false">http://nixshell.wordpress.com/?p=112#comment-5301</guid>
		<description><![CDATA[Your example of stty is unspecified in Posix.
A better solution would be to use tput(1).
It will work on Unix and Linux systems.

So far I tested it as working on Solaris, HP-UX, RHEL, and FreeBSD.

Width == `tput cols`
Height == `tput lines`

To get both at once:
printf &quot;cols\nlines\n&quot; &#124; tput -S
[. . .]

In regards to the resize(1) cmd, I would imagine that ccould be (re)implemented on any systems without it by using the above example in a shell function:

resize () {
  COLUMNS=`tput cols`
  LINES=`tput lines`
  export COLUMNS LINES
}

If you&#039;re on a Solaris system and choose to use the resize(1) that is found there, make sure to invoke it this way:
eval `resize`

That way the environment is updated.
a nice trick would be to put that in the users $PS1 prompt to evaluate anytime the shell prompts, presumably after a resize event.]]></description>
		<content:encoded><![CDATA[<p>Your example of stty is unspecified in Posix.<br />
A better solution would be to use tput(1).<br />
It will work on Unix and Linux systems.</p>
<p>So far I tested it as working on Solaris, HP-UX, RHEL, and FreeBSD.</p>
<p>Width == `tput cols`<br />
Height == `tput lines`</p>
<p>To get both at once:<br />
printf &#8220;cols\nlines\n&#8221; | tput -S<br />
[. . .]</p>
<p>In regards to the resize(1) cmd, I would imagine that ccould be (re)implemented on any systems without it by using the above example in a shell function:</p>
<p>resize () {<br />
  COLUMNS=`tput cols`<br />
  LINES=`tput lines`<br />
  export COLUMNS LINES<br />
}</p>
<p>If you&#8217;re on a Solaris system and choose to use the resize(1) that is found there, make sure to invoke it this way:<br />
eval `resize`</p>
<p>That way the environment is updated.<br />
a nice trick would be to put that in the users $PS1 prompt to evaluate anytime the shell prompts, presumably after a resize event.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: unixshell</title>
		<link>http://nixshell.wordpress.com/2009/09/08/get-the-width-of-the-terminal/#comment-5278</link>
		<dc:creator><![CDATA[unixshell]]></dc:creator>
		<pubDate>Tue, 08 Sep 2009 23:49:34 +0000</pubDate>
		<guid isPermaLink="false">http://nixshell.wordpress.com/?p=112#comment-5278</guid>
		<description><![CDATA[True. Fair comment, and as this blog is explicitly called &quot;*nixshell&quot; for that reason, I hold my hands up entirely.

As you cite: &quot;The stty utility is compliant with ... POSIX ... The ... operands ... speed, raw, ... size ... are extensions to that specification&quot;

That was really what I was trying to communicate - not that it is a Linux feature, but that it&#039;s a non-POSIX feature. I only had Linux and Solaris machines to hand when I posted; thanks for confirming that it works on the *BSD systems too.

Regarding &quot;diff&quot; - I was using GNU diff; sdiff can be useful too, but this post was inspired by a Linux-centric installation I have been working on where I can be sure of bash and GNU diff.

As a related item - I should probably post an entry on this subject - when writing scripts which assume (say) bash, the first line must say &quot;#!/bin/bash&quot;, not &quot;#!/bin/sh&quot;. It may even be necessary to get more specific, even to the level of &quot;#!/usr/local/perl/perl5.8/bin/perl&quot; if you require a certain feature, so that you can be sure that you have documented your requirements]]></description>
		<content:encoded><![CDATA[<p>True. Fair comment, and as this blog is explicitly called &#8220;*nixshell&#8221; for that reason, I hold my hands up entirely.</p>
<p>As you cite: &#8220;The stty utility is compliant with &#8230; POSIX &#8230; The &#8230; operands &#8230; speed, raw, &#8230; size &#8230; are extensions to that specification&#8221;</p>
<p>That was really what I was trying to communicate &#8211; not that it is a Linux feature, but that it&#8217;s a non-POSIX feature. I only had Linux and Solaris machines to hand when I posted; thanks for confirming that it works on the *BSD systems too.</p>
<p>Regarding &#8220;diff&#8221; &#8211; I was using GNU diff; sdiff can be useful too, but this post was inspired by a Linux-centric installation I have been working on where I can be sure of bash and GNU diff.</p>
<p>As a related item &#8211; I should probably post an entry on this subject &#8211; when writing scripts which assume (say) bash, the first line must say &#8220;#!/bin/bash&#8221;, not &#8220;#!/bin/sh&#8221;. It may even be necessary to get more specific, even to the level of &#8220;#!/usr/local/perl/perl5.8/bin/perl&#8221; if you require a certain feature, so that you can be sure that you have documented your requirements</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kamper</title>
		<link>http://nixshell.wordpress.com/2009/09/08/get-the-width-of-the-terminal/#comment-5277</link>
		<dc:creator><![CDATA[kamper]]></dc:creator>
		<pubDate>Tue, 08 Sep 2009 23:30:40 +0000</pubDate>
		<guid isPermaLink="false">http://nixshell.wordpress.com/?p=112#comment-5277</guid>
		<description><![CDATA[Saying &quot;Linux terminal&quot; isn&#039;t exactly fair.  &quot;stty size&quot; works for me on os x and OpenBSD and in particular, the STANDARDS section of the man page of the latter says:

&quot;The stty utility is compliant with the IEEE Std 1003.1-2004 (``POSIX&#039;&#039;) specification.

&quot;The flags [-ef] and the operands speed, crtscts, iuclc, imaxlabel, onlcr, olcuc, oxtabs, onoeot, echoke, altwerase, mdmbuf, flusho, pendin, xcase, tty, crt, kerninfo, columns, cols, rows, dec, extproc, raw, size, the compatibility modes and the control operations are extensions to that specification.&quot;

Your use of &quot;diff&quot;, though, is not very portable ;)]]></description>
		<content:encoded><![CDATA[<p>Saying &#8220;Linux terminal&#8221; isn&#8217;t exactly fair.  &#8220;stty size&#8221; works for me on os x and OpenBSD and in particular, the STANDARDS section of the man page of the latter says:</p>
<p>&#8220;The stty utility is compliant with the IEEE Std 1003.1-2004 (&#8220;POSIX&#8221;) specification.</p>
<p>&#8220;The flags [-ef] and the operands speed, crtscts, iuclc, imaxlabel, onlcr, olcuc, oxtabs, onoeot, echoke, altwerase, mdmbuf, flusho, pendin, xcase, tty, crt, kerninfo, columns, cols, rows, dec, extproc, raw, size, the compatibility modes and the control operations are extensions to that specification.&#8221;</p>
<p>Your use of &#8220;diff&#8221;, though, is not very portable <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
