bug-bash
[Top][All Lists]
Advanced

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

Re: Bug in select-command


From: Eduardo A . Bustamante López
Subject: Re: Bug in select-command
Date: Sat, 24 Jun 2017 09:46:47 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Sat, Jun 24, 2017 at 01:46:00PM +0200, address@hidden wrote:
[...]
> 
> ### DEFINE FUNCTIONS ###
> _config-keymap() {
>       # Select keymap
>               # find keymap list, cut directory path and sort
>                       local list_keymaps=( $(find /usr/share/kbd/keymaps/ 
> -type f -name 
> *.map.gz | grep -Eo [^/]*.map.gz | sort -V) )
>               # cut suffixes
>                       list_keymaps=( address@hidden )
> 
>               select locale_keymap in address@hidden; do
>                       if [[ "$REPLY" -ge 1 && "$REPLY" -lt address@hidden ]]; 
> then
>                               echo ${locale_keymap}; break
>                       fi
>               done
> }
> 
> ### MAIN PROGRAMM ###
> clear
> _config-keymap
> 
I don't have `/usr/share/kbd/keymaps/' in my system.

    address@hidden:~$ ls -l /usr/share/kbd/keymaps/
    ls: cannot access '/usr/share/kbd/keymaps/': No such file or directory

>From what I can tell, I get these keymaps by installing `console-data'
in my Debian system, although these are installed under `/usr/share/keymaps/',
and have different extensions (e.g.
`/usr/share/keymaps/i386/qwerty/pc110.kmap.gz')

~~~~~

I think this is an easier way to reproduce the problem. I have a terminal
window with the following dimensions:

  address@hidden:~$ declare -p COLUMNS LINES
  declare -- COLUMNS="191"
  declare -- LINES="49"

  address@hidden:~$ bash --version | head -n1
  GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)

Running the script in `interactive' mode (which triggers calls to
`get_new_window_size' through `get_tty_state' when checkwinsize is
enabled), lays out the options on seven columns:

  address@hidden:~$ bash -i script 
  $- himB
  cols 191
  1) aaaaaaaaaaaaaaaaaaaa    8) aaaaaaaaaaaaaaaaaaaa  15) bbbbbbbbbbbbbbbbbbbb  
22) cccccccccccccccccccc  29) dddddddddddddddddddd  36) eeeeeeeeeeeeeeeeeeee  
43) ffffffffffffffffffff
  2) aaaaaaaaaaaaaaaaaaaa    9) bbbbbbbbbbbbbbbbbbbb  16) bbbbbbbbbbbbbbbbbbbb  
23) cccccccccccccccccccc  30) dddddddddddddddddddd  37) eeeeeeeeeeeeeeeeeeee  
44) ffffffffffffffffffff
  3) aaaaaaaaaaaaaaaaaaaa   10) bbbbbbbbbbbbbbbbbbbb  17) cccccccccccccccccccc  
24) cccccccccccccccccccc  31) dddddddddddddddddddd  38) eeeeeeeeeeeeeeeeeeee  
45) ffffffffffffffffffff
  4) aaaaaaaaaaaaaaaaaaaa   11) bbbbbbbbbbbbbbbbbbbb  18) cccccccccccccccccccc  
25) dddddddddddddddddddd  32) dddddddddddddddddddd  39) eeeeeeeeeeeeeeeeeeee  
46) ffffffffffffffffffff
  5) aaaaaaaaaaaaaaaaaaaa   12) bbbbbbbbbbbbbbbbbbbb  19) cccccccccccccccccccc  
26) dddddddddddddddddddd  33) eeeeeeeeeeeeeeeeeeee  40) eeeeeeeeeeeeeeeeeeee  
47) ffffffffffffffffffff
  6) aaaaaaaaaaaaaaaaaaaa   13) bbbbbbbbbbbbbbbbbbbb  20) cccccccccccccccccccc  
27) dddddddddddddddddddd  34) eeeeeeeeeeeeeeeeeeee  41) ffffffffffffffffffff  
48) ffffffffffffffffffff
  7) aaaaaaaaaaaaaaaaaaaa   14) bbbbbbbbbbbbbbbbbbbb  21) cccccccccccccccccccc  
28) dddddddddddddddddddd  35) eeeeeeeeeeeeeeeeeeee  42) ffffffffffffffffffff
  #? q

Whereas running the same script in `non-interactive' mode results in three
columns.

  address@hidden:~$ bash  script 
  $- hB
  cols 191
   1) aaaaaaaaaaaaaaaaaaaa  17) cccccccccccccccccccc  33) eeeeeeeeeeeeeeeeeeee
   2) aaaaaaaaaaaaaaaaaaaa  18) cccccccccccccccccccc  34) eeeeeeeeeeeeeeeeeeee
   3) aaaaaaaaaaaaaaaaaaaa  19) cccccccccccccccccccc  35) eeeeeeeeeeeeeeeeeeee
   4) aaaaaaaaaaaaaaaaaaaa  20) cccccccccccccccccccc  36) eeeeeeeeeeeeeeeeeeee
   5) aaaaaaaaaaaaaaaaaaaa  21) cccccccccccccccccccc  37) eeeeeeeeeeeeeeeeeeee
   6) aaaaaaaaaaaaaaaaaaaa  22) cccccccccccccccccccc  38) eeeeeeeeeeeeeeeeeeee
   7) aaaaaaaaaaaaaaaaaaaa  23) cccccccccccccccccccc  39) eeeeeeeeeeeeeeeeeeee
   8) aaaaaaaaaaaaaaaaaaaa  24) cccccccccccccccccccc  40) eeeeeeeeeeeeeeeeeeee
   9) bbbbbbbbbbbbbbbbbbbb  25) dddddddddddddddddddd  41) ffffffffffffffffffff
  10) bbbbbbbbbbbbbbbbbbbb  26) dddddddddddddddddddd  42) ffffffffffffffffffff
  11) bbbbbbbbbbbbbbbbbbbb  27) dddddddddddddddddddd  43) ffffffffffffffffffff
  12) bbbbbbbbbbbbbbbbbbbb  28) dddddddddddddddddddd  44) ffffffffffffffffffff
  13) bbbbbbbbbbbbbbbbbbbb  29) dddddddddddddddddddd  45) ffffffffffffffffffff
  14) bbbbbbbbbbbbbbbbbbbb  30) dddddddddddddddddddd  46) ffffffffffffffffffff
  15) bbbbbbbbbbbbbbbbbbbb  31) dddddddddddddddddddd  47) ffffffffffffffffffff
  16) bbbbbbbbbbbbbbbbbbbb  32) dddddddddddddddddddd  48) ffffffffffffffffffff
  #? q

The script:

  address@hidden:~$ cat script 
  #!/bin/bash
  shopt -s checkwinsize
  
  options=(
  aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 
aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 
aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa
  bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb 
bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb 
bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb
  cccccccccccccccccccc cccccccccccccccccccc cccccccccccccccccccc 
cccccccccccccccccccc cccccccccccccccccccc cccccccccccccccccccc 
cccccccccccccccccccc cccccccccccccccccccc
  dddddddddddddddddddd dddddddddddddddddddd dddddddddddddddddddd 
dddddddddddddddddddd dddddddddddddddddddd dddddddddddddddddddd 
dddddddddddddddddddd dddddddddddddddddddd
  eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee 
eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee 
eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee
  ffffffffffffffffffff ffffffffffffffffffff ffffffffffffffffffff 
ffffffffffffffffffff ffffffffffffffffffff ffffffffffffffffffff 
ffffffffffffffffffff ffffffffffffffffffff
  )
  
  echo \$- $-
  echo cols $(tput cols)
  select opt in "address@hidden"; do
    break
  done


AFAICT, this is intentional. There's another option though. If you read
https://lists.gnu.org/archive/html/help-bash/2015-03/msg00005.html, you'll see
why the following works:

  # seven columns, non-interactive
  address@hidden:~$ bash script
  $- hB
  cols 80
  1) aaaaaaaaaaaaaaaaaaaa    8) aaaaaaaaaaaaaaaaaaaa  15) bbbbbbbbbbbbbbbbbbbb  
22) cccccccccccccccccccc  29) dddddddddddddddddddd  36) eeeeeeeeeeeeeeeeeeee  
43) ffffffffffffffffffff
  2) aaaaaaaaaaaaaaaaaaaa    9) bbbbbbbbbbbbbbbbbbbb  16) bbbbbbbbbbbbbbbbbbbb  
23) cccccccccccccccccccc  30) dddddddddddddddddddd  37) eeeeeeeeeeeeeeeeeeee  
44) ffffffffffffffffffff
  3) aaaaaaaaaaaaaaaaaaaa   10) bbbbbbbbbbbbbbbbbbbb  17) cccccccccccccccccccc  
24) cccccccccccccccccccc  31) dddddddddddddddddddd  38) eeeeeeeeeeeeeeeeeeee  
45) ffffffffffffffffffff
  4) aaaaaaaaaaaaaaaaaaaa   11) bbbbbbbbbbbbbbbbbbbb  18) cccccccccccccccccccc  
25) dddddddddddddddddddd  32) dddddddddddddddddddd  39) eeeeeeeeeeeeeeeeeeee  
46) ffffffffffffffffffff
  5) aaaaaaaaaaaaaaaaaaaa   12) bbbbbbbbbbbbbbbbbbbb  19) cccccccccccccccccccc  
26) dddddddddddddddddddd  33) eeeeeeeeeeeeeeeeeeee  40) eeeeeeeeeeeeeeeeeeee  
47) ffffffffffffffffffff
  6) aaaaaaaaaaaaaaaaaaaa   13) bbbbbbbbbbbbbbbbbbbb  20) cccccccccccccccccccc  
27) dddddddddddddddddddd  34) eeeeeeeeeeeeeeeeeeee  41) ffffffffffffffffffff  
48) ffffffffffffffffffff
  7) aaaaaaaaaaaaaaaaaaaa   14) bbbbbbbbbbbbbbbbbbbb  21) cccccccccccccccccccc  
28) dddddddddddddddddddd  35) eeeeeeeeeeeeeeeeeeee  42) ffffffffffffffffffff
  #? ^C
  
  address@hidden:~$ cat script 
  #!/bin/bash
  shopt -s checkwinsize
  
  options=(
  aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 
aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 
aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa
  bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb 
bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb 
bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb
  cccccccccccccccccccc cccccccccccccccccccc cccccccccccccccccccc 
cccccccccccccccccccc cccccccccccccccccccc cccccccccccccccccccc 
cccccccccccccccccccc cccccccccccccccccccc
  dddddddddddddddddddd dddddddddddddddddddd dddddddddddddddddddd 
dddddddddddddddddddd dddddddddddddddddddd dddddddddddddddddddd 
dddddddddddddddddddd dddddddddddddddddddd
  eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee 
eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee 
eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee
  ffffffffffffffffffff ffffffffffffffffffff ffffffffffffffffffff 
ffffffffffffffffffff ffffffffffffffffffff ffffffffffffffffffff 
ffffffffffffffffffff ffffffffffffffffffff
  )
  
  echo \$- $-
  echo cols $(tput cols)
  /bin/true # THIS
  select opt in "address@hidden"; do
    break
  done

For some reason though, the following fails to update the value of COLUMNS:

  address@hidden:~$ cat script 
  #!/bin/bash
  shopt -s checkwinsize
  
  options=(
  aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 
aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 
aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa
  bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb 
bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb 
bbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbb
  cccccccccccccccccccc cccccccccccccccccccc cccccccccccccccccccc 
cccccccccccccccccccc cccccccccccccccccccc cccccccccccccccccccc 
cccccccccccccccccccc cccccccccccccccccccc
  dddddddddddddddddddd dddddddddddddddddddd dddddddddddddddddddd 
dddddddddddddddddddd dddddddddddddddddddd dddddddddddddddddddd 
dddddddddddddddddddd dddddddddddddddddddd
  eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee 
eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee 
eeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee
  ffffffffffffffffffff ffffffffffffffffffff ffffffffffffffffffff 
ffffffffffffffffffff ffffffffffffffffffff ffffffffffffffffffff 
ffffffffffffffffffff ffffffffffffffffffff
  )
  
  echo \$- $-
  echo cols $(tput cols)
  command true # this should trigger?
  select opt in "address@hidden"; do
    break
  done

So the trick is to run an external command in foreground. To see why this
works, read:
http://git.savannah.gnu.org/cgit/bash.git/tree/jobs.c?h=devel#n3390

-- 
Eduardo Bustamante
https://dualbus.me/



reply via email to

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