#1075768 coreutils: ls doesn't honour COLUMNS if writing to a teletype

Package:
coreutils
Source:
coreutils
Description:
GNU core utilities
Submitter:
наб
Date:
2024-07-04 19:15:03 UTC
Severity:
normal
#1075768#5
Date:
2024-07-04 16:29:48 UTC
From:
To:
Dear Maintainer,

Quoth POSIX.1-2024:
103406  ENVIRONMENT VARIABLES
103407  The following environment variables shall affect the execution of ls:
103408  COLUMNS  Override the system-selected horizontal display line size, used to determine the
103409           column position width for writing multiple text-column output. See XBD Chapter
103410           8 (on page 167) for valid values and results when it is unset or null. The ls utility
103411           shall use this value to calculate how many pathname text columns to write (see
103412           −C). The column width chosen to write the names of files in any given directory
103413           shall be constant. Filenames shall not be truncated to fit into the multiple text-
103414           column output.

Quoth UNIX™ System V ‒ Release 2.0 User Reference Manual, DEC™ Processors (1984):
  There are three major listing formats.  The default format is to list one entry
  per line, the -C and -x options enable multi-column formats, and the -m
  option enables stream output format in which files are listed across the page,
  separated by commas.  In order to determine output formats for the -C, -x,
  and -m options, /s uses an environment variable, COLUMNS, to determine the
  number of character positions available on one output line.  If this variable is
  not set, the terminfo database is used to determine the number of columns,
  based on the environment variable TERM.  If this information cannot be
  obtained, 80 columns are assumed.

Compare:
  $ /bin/ls
  a    baba.gif  boot.dump  dead.letter  dump1.stty   dump1.worms.c  dump2.stty   dump2.worms.c  equivs             rustup-init     setup.log  tarta.d  worms.c
  awk  bin       code       dump1.cmd    dump1.worms  dump2.cmd      dump2.worms  dupa           reportbug.report~  rustup-init.sh  src        worms
  $ COLUMNS=80 /bin/ls
  a    baba.gif  boot.dump  dead.letter  dump1.stty   dump1.worms.c  dump2.stty   dump2.worms.c  equivs             rustup-init     setup.log  tarta.d  worms.c
  awk  bin       code       dump1.cmd    dump1.worms  dump2.cmd      dump2.worms  dupa           reportbug.report~  rustup-init.sh  src        worms

Best,

#1075768#10
Date:
2024-07-04 19:11:32 UTC
From:
To:
Right, both POSIX 2003 and 2008 say that COLUMNS should override any auto width determination.
However since the beginning, GNU ls has the -w option to override the width,
and so leaves $COLUMNS as something that is auto set (and usually is by the shell).
Since changing this to align with POSIX adds no new functionality,
I'm reluctant to adjust this at this stage, in case COLUMNS is set
incorrectly / inadvertently for some users.
We could safely change this I suppose, gated with the POSIXLY_CORRECT env var.

cheers,
Pádraig.