bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in select-command


From: Chet Ramey
Subject: Re: Bug in select-command
Date: Sun, 25 Jun 2017 17:28:51 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

On 6/24/17 1:38 PM, Eduardo A. Bustamante López wrote:
> On Sat, Jun 24, 2017 at 01:17:23PM -0400, Chet Ramey wrote:
> [...]
>> You haven't exported these.  If you had, the subshell started to run the
>> script would have the correct values.
> 
> Hm. I think this may be a documentation / usability problem.

It's a documentation problem, since the documentation doesn't completely
reflect the behavior.

> The manual states the following:
> 
>   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.

Yes, and the checkwinsize description has the details of how it does that.

>   [...]
> 
>   checkwinsize
>         If set, bash checks the window size after each command and, if
>         necessary, updates the values of LINES and COLUMNS.

This should be after each external (non-builtin) command.

> Furthermore, POSIX [1] says the following:
> 
>   COLUMNS
>         This variable shall represent a decimal integer >0 used to indicate
>         the user's preferred width in column positions for the terminal
>         screen or window; see Column Position. If this variable is unset or
>         null, the implementation determines the number of columns,
>         appropriate for the terminal or window, in an unspecified manner.

This is Posix-speak for "we don't know how it does it, but we assume the
appropriate value is put into COLUMNS and exported somehow," since "the
implementation" doesn't mean "the shell".


>         When COLUMNS is set, any terminal-width information implied by TERM
>         is overridden. Users and conforming applications should not set
>         COLUMNS unless they wish to override the system selection and produce
>         output unrelated to the terminal characteristics.
> 
>         Users *should not need to set this variable in the environment*
>         unless there is a specific reason to override the implementation's
>         default behavior, such as to display data in an area arbitrarily
>         smaller than the terminal or window.

In this case, the implementation's default behavior is to not export
COLUMNS or, apparently, set it in non-interactive shells.

> 
> So, from the manual alone, I know the following:
> 
> - `select' uses the COLUMNS variable to determine the terminal width
> - the value of COLUMNS is automatically set if the `checkwinsize' option is
>   enabled (** restrictions apply).
> - bash checks the window size after each command

So it's a documentation problem concerning what "each command" means.

> I have the following problems with the documentation:
> 
> - It seems to imply that it's set automatically *when* `checkwinsize' is

That's not what it says.  It says "if", not "when".  The description of
`checkwinsize' should describe the circumstances under which it acts.

> - It doesn't mention that the window size is NOT checked after *builtin*
>   commands.

And that is the problem.

> - POSIX recommends against exporting the COLUMNS variable.

No, it doesn't. It says that it should usually not be necessary.  If you
find that your implementation doesn't make the value available, you have
the option to export it.
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]