watch breaks COLUMNS when used to run a script inside docker container with `docker exec -ti container_name /script_name.sh`
When calling a script inside a docker container, watch
fails to get current terminal COLUMNS
value and defaults to WIDTH_FALLBACK
which is then used for the docker exec -ti container_name /script_name.sh
command for it's terminal dimensions - which is subsequently incorrect (actually not set) for script_name.sh
- COLUMNS
is NOT set or available inside the container.
https://gitlab.com/procps-ng/procps/-/blob/master/src/watch.c?ref_type=heads#L1041
When running the docker exec -ti container_name /script_name.sh
without using watch
, all is well.
e.g.
command | COLUMNS value |
---|---|
watch -cd 'docker exec -ti container_name /script_name.sh' |
80 (COLUMNS is not set inside the container either) |
docker exec -ti container_name /script_name.sh |
211 (or whatever the current terminal dimensions are) |
watch -cd "docker exec -ti container_name bash -c 'tput cols'" |
80 (COLUMNS is not set inside the container either) |
docker exec -ti container_name bash -c 'tput cols' |
211 (or whatever the current terminal dimensions are) |
It is necessary to pass the COLUMNS
value into docker
when using watch
i.e. docker exec -ti -e COLUMNS=$COLUMNS container_name /script_name.sh
Additional info:
$ watch --version
watch from procps-ng 3.3.17
$ neofetch --stdout
XX@XXXX
-------
OS: Linux Mint 21.1 x86_64
Host: HP ENVY 17 Notebook PC XXXXXXXXXXXXXXXXXXXXXXXXX
Kernel: 5.15.0-89-generic
Uptime: 21 days, 11 hours, 21 mins
Packages: 4913 (dpkg), 21 (brew)
Shell: bash 5.1.16
Resolution: 1920x1080
DE: Cinnamon 5.6.8
WM: Mutter (Muffin)
WM Theme: Mint-Y-Dark (Mint-Y-Dark)
Theme: Mint-Y-Dark [GTK2/3]
Icons: Mint-Y-Dark [GTK2/3]
Terminal: terminator
CPU: Intel i7-4710MQ (8) @ 3.500GHz
GPU: Intel 4th Gen Core Processor
GPU: NVIDIA GeForce 840M
Memory: 10267MiB / 11893MiB
$ terminator --version
terminator 2.1.1
$ bash --version
bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Edited by David Pesticcio