On Sun, May 10, 2026 at 7:02 AM Ilya Tsoy via Bug reports for the GNU
Bourne Again SHell <[email protected]> wrote:
>
> Fix:
> A documentation patch clarifying that LINES/COLUMNS may be updated in
> any shell where checkwinsize is enabled and a TTY is available, not
> only interactive shells.

The current devel branch (commit 669b32f676) manual says this:
COLUMNS Used by the select compound command to determine the terminal
width when printing selection lists. Automatically set if the
checkwinsize option is enabled or in an interactive shell upon receipt
of a SIGWINCH.
LINES Used by the select compound command to determine the column
length for printing selection lists. Automatically set if the
checkwinsize option is enabled or in an interactive shell upon receipt
of a SIGWINCH.

In fact, they're currently set in a noninteractive shell after any
external command runs, if checkwinsize is enabled.

They may as well be made to work the same in a noninteractive shell as
they do in an interactive one.

https://lists.gnu.org/archive/html/bug-bash/2026-04/msg00013.html
On Mon, Apr 6, 2026 at 11:28 AM Chet Ramey <[email protected]> wrote:
>
> On 4/2/26 11:22 PM, Zachary Santer wrote:
>
> > Why not just set the values of LINES and COLUMNS when the
> > script begins to run,
>
> Because users expect the shell to honor the values they pass in the
> environment.

Bash could disable checkwinsize automatically at the beginning of
script execution if either COLUMNS or LINES appears in the script's
environment. set -o posix is enabled automatically if POSIXLY_CORRECT
appears in the script's environment, so there's kind of an analogous
precedent.

If the user wants to set either variable themselves in any other way,
disabling checkwinsize first is effectively already necessary.

> > or whenever checkwinsize is enabled, if it had
> > been disabled?
>
> For the same reason. No reason to reset the window size if the user has
> specified something different in the environment, but by setting it, the
> user has indicated an interest in its effects when running external
> programs.

Bash could even disable checkwinsize any time LINES or COLUMNS is set,
but that might be overkill.

> > And then upon SIGWINCH also in a noninteractive shell?
>
> There haven't really been requests to do this, and it would also override
> any environment settings.

I've got a simple script that will run another program and print lines
from that program, clearing and overwriting the prior line each time
unless that line matches on "*error:*" or one of a few other patterns.
For it to work, lines that match none of the patterns have to be
truncated at ${COLUMNS} characters. That script is still trapped in
bash 4.2-land, using $( tput cols ) to get the information it needs.
But hopefully this illustrates how this functionality would be useful
in a noninteractive shell.

Ilya, be wary of using any all-caps variables in a shell script. You
can see how many bash has already reserved for its own use, and
external programs tend to take all-caps environment variables for
things they need. Outside of those things, I tend to only use all-caps
variables in bash scripts for constant, integer values, but that's
just me.

Zack

Reply via email to