2

Im trying to detect when my menu is resized using trap "echo resized" SIGWINCH but it doesnt seem to be detecting it. Im currently using ubuntu 20.04 and i am using a bash script to do this. The trap command is at the top of my script. Why is it not executing?

Quantum
  • 59
  • 5
  • 1
    try removing the `SIG` prefix as: `trap 'echo resized' WINCH`. Tested it working with `gnome-terminal` and `xterm`. – Léa Gris Nov 07 '20 at 14:35
  • Question was voted down by someone who did not understand the question. Anyone able to answer the question can easily understand it. It is a good question. – Dino Dini Jun 22 '22 at 21:27
  • Solution proposed by @Léa Gris worked for me also (Konsole on KDE Plasma, bash 5.1). Thus `WINCH` instead of `SIGWINCH` was required for the `trap` to catch the signal. If `read` is required instead of a loop, remember to set a timeout to the `read`, e.g. `read -t 0.5` (this works in most cases, see also https://github.com/dylanaraps/fff/issues/48#issuecomment-453808371). – wiredolphin Mar 11 '23 at 14:02

1 Answers1

5

According to bash manual (man bash):

If bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes.

You can verify this with:

trap 'echo resized' SIGWINCH

while true; do
    sleep 1
done
pynexj
  • 19,215
  • 5
  • 38
  • 56