Debian Bug report logs - #628638
bash.1: "shopt -s checkwinsize" has no effect in non-interactive shells

version graph

Package: bash; Maintainer for bash is Matthias Klose <doko@debian.org>; Source for bash is src:bash.

Reported by: Leslie A Rhorer <lrhorer@satx.rr.com>

Date: Mon, 30 May 2011 22:48:01 UTC

Severity: minor

Tags: patch, upstream

Found in version bash/4.1-3

Forwarded to http://thread.gmane.org/gmane.comp.shells.bash.bugs/16651

Reply or subscribe to this bug.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#628638; Package bash. (Mon, 30 May 2011 22:48:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leslie A Rhorer <lrhorer@satx.rr.com>:
New Bug report received and forwarded. Copy sent to Matthias Klose <doko@debian.org>. (Mon, 30 May 2011 22:48:04 GMT) Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Leslie A Rhorer <lrhorer@satx.rr.com>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: bash: winndow size not tracked in child shell
Date: Mon, 30 May 2011 17:44:30 -0500
Package: bash
Version: 4.1-3
Severity: normal

The $COLUMNS variable seems to work properly in a terminal window (with shopt -s checkwinsize), but in a child script, the $COLUMNS variable is null no matter what I try, even if the windows is resized while running the script.

-- System Information:
Debian Release: 6.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages bash depends on:
ii  base-files                6.0            Debian base system miscellaneous f
ii  dash                      0.5.5.1-7.4    POSIX-compliant shell
ii  debianutils               3.4            Miscellaneous utilities specific t
ii  libc6                     2.11.2-10      Embedded GNU C Library: Shared lib
ii  libncurses5               5.7+20100313-5 shared libraries for terminal hand

Versions of packages bash recommends:
ii  bash-completion               1:1.2-3    programmable completion for the ba

Versions of packages bash suggests:
pn  bash-doc                      <none>     (no description available)

-- Configuration Files:
/etc/bash.bashrc changed:
alias ll="ls -la"
[ -z "$PS1" ] && return
shopt -s checkwinsize
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
if [ -x /usr/lib/command-not-found ]; then
	function command_not_found_handle {
	        # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
		   /usr/bin/python /usr/lib/command-not-found -- $1
                   return $?
		else
		   return 127
		fi
	}
fi


-- no debconf information




Information forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#628638; Package bash. (Tue, 31 May 2011 00:00:27 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Matthias Klose <doko@debian.org>. (Tue, 31 May 2011 00:00:27 GMT) Full text and rfc822 format available.

Message #10 received at 628638@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: Leslie A Rhorer <lrhorer@satx.rr.com>
Cc: 628638@bugs.debian.org
Subject: Re: bash: window size not tracked in child shell
Date: Mon, 30 May 2011 18:57:19 -0500
retitle 628638 bash.1: "shopt -s checkwinsize" has no effect in non-interactive shells
severity 628638 minor
tags 628638 + upstream
quit

Hi Leslie,

Leslie A Rhorer wrote:

> The $COLUMNS variable seems to work properly in a terminal window
> (with shopt -s checkwinsize), but in a child script, the $COLUMNS
> variable is null no matter what I try, even if the windows is
> resized while running the script.

I tried to reproduce this like so:

	cat >$HOME/bin/echocolumns <<\EOF
	#!/bin/bash
	shopt -s checkwinsize
	read tmp
	echo $COLUMNS
	EOF

	chmod +x $HOME/bin/echocolumns
	echocolumns
	[resize the terminal, then hit enter]

Indeed, it printed a blank line instead of a number of columns.  But
I can't really fault bash for this behavior when

	#!/bin/sh
	tput cols

works reliably.

Do you agree?  If so, could you suggest a patch for the manpage?  If
not, what would be a better behavior?

Thanks for reporting,
Jonathan




Changed Bug title to 'bash.1: "shopt -s checkwinsize" has no effect in non-interactive shells' from 'bash: winndow size not tracked in child shell' Request was from Jonathan Nieder <jrnieder@gmail.com> to control@bugs.debian.org. (Tue, 31 May 2011 00:00:29 GMT) Full text and rfc822 format available.

Severity set to 'minor' from 'normal' Request was from Jonathan Nieder <jrnieder@gmail.com> to control@bugs.debian.org. (Tue, 31 May 2011 00:00:29 GMT) Full text and rfc822 format available.

Added tag(s) upstream. Request was from Jonathan Nieder <jrnieder@gmail.com> to control@bugs.debian.org. (Tue, 31 May 2011 00:00:30 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#628638; Package bash. (Wed, 01 Jun 2011 01:54:08 GMT) Full text and rfc822 format available.

Acknowledgement sent to <lrhorer@satx.rr.com>:
Extra info received and forwarded to list. Copy sent to Matthias Klose <doko@debian.org>. (Wed, 01 Jun 2011 01:54:08 GMT) Full text and rfc822 format available.

Message #21 received at 628638@bugs.debian.org (full text, mbox):

From: "Leslie Rhorer" <lrhorer@satx.rr.com>
To: "'Jonathan Nieder'" <jrnieder@gmail.com>
Cc: <628638@bugs.debian.org>
Subject: RE: bash: window size not tracked in child shell
Date: Tue, 31 May 2011 20:50:20 -0500
> -----Original Message-----
> From: Jonathan Nieder [mailto:jrnieder@gmail.com]
> Sent: Monday, May 30, 2011 6:57 PM
> To: Leslie A Rhorer
> Cc: 628638@bugs.debian.org
> Subject: Re: bash: window size not tracked in child shell
> 
> retitle 628638 bash.1: "shopt -s checkwinsize" has no effect in non-
> interactive shells
> severity 628638 minor
> tags 628638 + upstream
> quit
> 
> Hi Leslie,
> 
> Leslie A Rhorer wrote:
> 
> > The $COLUMNS variable seems to work properly in a terminal window
> > (with shopt -s checkwinsize), but in a child script, the $COLUMNS
> > variable is null no matter what I try, even if the windows is
> > resized while running the script.
> 
> I tried to reproduce this like so:
> 
> 	cat >$HOME/bin/echocolumns <<\EOF
> 	#!/bin/bash
> 	shopt -s checkwinsize
> 	read tmp
> 	echo $COLUMNS
> 	EOF
> 
> 	chmod +x $HOME/bin/echocolumns
> 	echocolumns
> 	[resize the terminal, then hit enter]
> 
> Indeed, it printed a blank line instead of a number of columns.  But
> I can't really fault bash for this behavior when
> 
> 	#!/bin/sh
> 	tput cols
> 
> works reliably.

OK, why?  Why doesn't sending the process a SIGWINCH force it to update the
$COLUMNS variable?

> Do you agree?  If so, could you suggest a patch for the manpage?  If
> not, what would be a better behavior?
> 
> Thanks for reporting,
> Jonathan

Well, I'm not quite sure what you mean by "can't really fault bash...", but
yes, if there is an acceptable work-around, I suppose merely updating the
man page is sufficient.  What about the $LINES variable?  How can the script
obtain it?  Assuming there is a way, I would suggest something very close to
your report above.  Perhaps:

"The checkwinsize parameter has no effect in non-interactive shells.  The
$COLUMNS and $LINES parameters will remain null unless updated by the script
itself.  EXAMPLE: If one must obtain the width of the screen, one may set
COLUMNS=$( tput cols ).  To obtain the window height, set LINES="

Followed by however that is done.





Information forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#628638; Package bash. (Wed, 01 Jun 2011 02:51:14 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Matthias Klose <doko@debian.org>. (Wed, 01 Jun 2011 02:51:16 GMT) Full text and rfc822 format available.

Message #26 received at 628638@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: bug-bash@gnu.org
Cc: 628638@bugs.debian.org, Leslie Rhorer <lrhorer@satx.rr.com>
Subject: [PATCH/RFC] bash.1: "shopt -s checkwinsize" has no effect in non-interactive shells
Date: Tue, 31 May 2011 21:49:50 -0500
Explain that COLUMNS and LINES are not set automatically in
non-interactive shells, and recommend direct use of the tput utility
from ncurses as a replacement.

Fixes: http://bugs.debian.org/628638
Reported-by: Leslie A Rhorer <lrhorer@satx.rr.com>
Helped-by: Leslie A Rhorer <lrhorer@satx.rr.com>
---
Hi Chet et al,

Here's a quick documentation patch, based on the report mentioned
above.  Thoughts of all kinds welcome.

 doc/bash.1 |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/doc/bash.1 b/doc/bash.1
index 1890b3c..4df0986 100644
--- a/doc/bash.1
+++ b/doc/bash.1
@@ -1802,7 +1802,10 @@ being closed.
 .TP
 .B COLUMNS
 Used by the \fBselect\fP builtin command to determine the terminal width
-when printing selection lists.  Automatically set upon receipt of a SIGWINCH.
+when printing selection lists.  Automatically set in interactive shells
+upon receipt of a SIGWINCH.
+To obtain the width of the terminal in a non-interactive shell,
+use \fBCOLUMNS\fP=$(tput cols).
 .TP
 .B COMPREPLY
 An array variable from which \fBbash\fP reads the possible completions
@@ -2021,9 +2024,12 @@ This variable determines the locale category used for number formatting.
 .TP
 .B LINES
 Used by the \fBselect\fP builtin command to determine the column length
-for printing selection lists.  Automatically set upon receipt of a
+for printing selection lists.  Automatically set in interactive shells
+upon receipt of a
 .SM
 .BR SIGWINCH .
+To obtain the width of the terminal in a non-interactive shell,
+use \fBLINES\fP=$(tput lines).
 .TP
 .B MAIL
 If this parameter is set to a file name and the
@@ -8732,8 +8738,8 @@ above).  The shell always
 postpones exiting if any jobs are stopped.
 .TP 8
 .B checkwinsize
-If set, \fBbash\fP checks the window size after each command
-and, if necessary, updates the values of
+If set and the shell is interactive, \fBbash\fP checks the window size
+after each command and, if necessary, updates the values of
 .SM
 .B LINES
 and
-- 
1.7.5.3





Added tag(s) patch. Request was from Jonathan Nieder <jrnieder@gmail.com> to control@bugs.debian.org. (Wed, 01 Jun 2011 03:03:03 GMT) Full text and rfc822 format available.

Set Bug forwarded-to-address to 'http://thread.gmane.org/gmane.comp.shells.bash.bugs/16651'. Request was from Jonathan Nieder <jrnieder@gmail.com> to control@bugs.debian.org. (Wed, 01 Jun 2011 03:03:03 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#628638; Package bash. (Wed, 01 Jun 2011 18:54:10 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Matthias Klose <doko@debian.org>. (Wed, 01 Jun 2011 18:54:10 GMT) Full text and rfc822 format available.

Message #35 received at 628638@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: Leslie Rhorer <lrhorer@satx.rr.com>
Cc: 628638@bugs.debian.org
Subject: Re: [PATCH/RFC] bash.1: "shopt -s checkwinsize" has no effect in non-interactive shells
Date: Wed, 1 Jun 2011 13:44:24 -0500
Jonathan Nieder wrote:
> Leslie Rhorer wrote:

>> Yeah, I think that's fine.  Feel free to close the bug report.
>
> Thanks for looking it over (and thanks for reporting the problem in
> the first place).  I'll leave the bug open until the patch or
> something like it is applied.

Gah!  Wrong address; sorry for the noise.




Information forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#628638; Package bash. (Sun, 05 Jun 2011 00:48:07 GMT) Full text and rfc822 format available.

Acknowledgement sent to chet.ramey@case.edu:
Extra info received and forwarded to list. Copy sent to Matthias Klose <doko@debian.org>. (Sun, 05 Jun 2011 00:48:07 GMT) Full text and rfc822 format available.

Message #40 received at 628638@bugs.debian.org (full text, mbox):

From: Chet Ramey <chet.ramey@case.edu>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: bug-bash@gnu.org, Leslie Rhorer <lrhorer@satx.rr.com>, 628638@bugs.debian.org, chet.ramey@case.edu
Subject: Re: [PATCH/RFC] bash.1: "shopt -s checkwinsize" has no effect in non-interactive shells
Date: Sat, 04 Jun 2011 20:39:28 -0400
On 5/31/11 10:49 PM, Jonathan Nieder wrote:
> Explain that COLUMNS and LINES are not set automatically in
> non-interactive shells, and recommend direct use of the tput utility
> from ncurses as a replacement.

Thanks for the report, though the tput recommendation doesn't belong in
a manual page.  It's more appropriate for an FAQ or a bash guide.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Thu Apr 24 07:38:34 2014; Machine Name: beach.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.