> -----Original Message----- > From: Jonathan Nieder [mailto:[email protected]] > Sent: Monday, May 30, 2011 6:57 PM > To: Leslie A Rhorer > Cc: [email protected] > 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. -- To UNSUBSCRIBE, email to [email protected] with a subject of "unsubscribe". Trouble? Contact [email protected]

