URL:
  <https://savannah.gnu.org/bugs/?67679>

                 Summary: Exit due to -e can be canceled by ERR trap
                   Group: The GNU Bourne-Again SHell
               Submitter: None
               Submitted: Thu 06 Nov 2025 10:53:59 AM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Thu 06 Nov 2025 10:53:59 AM UTC By: Anonymous
Configuration Information
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fno-omit-frame-pointer
-mno-omit-leaf-frame-pointer -flto=auto -ffat-lto-objects
-fstack-protector-strong -fstack-clash-protection -Wformat
-Werror=format-security -fcf-protection -Wall
uname output: Linux VMX-T16-7661 6.8.0-86-generic #87-Ubuntu SMP
PREEMPT_DYNAMIC Mon Sep 22 18:03:36 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 21
Release Status: release

Description:
    The man-page says under set -e: "...A trap on ERR, if set, is executed
before the shell exits. ..."
    If such a handler sets "set +e", the original flow is resumed after the
handler exits.
    I would expect that once the exit due to "set -e" is initiated, it should
not be cancelable.

The example script in Repeat-By (also find attached) produces the following
output:
    main: the next command will fail
    handler: the next command will fail
    handler: after failing command
    main: after failing command

Expected output:
    main: the next command will fail
    handler: the next command will fail
    handler: after failing command

Repeat-By:
    handler () {
      set +e
      echo "handler: the next command will fail"
      false
      echo "handler: after failing command"
    }

    trap handler ERR

    set -e
    echo "main: the next command will fail"
    false
    echo "main: after failing command"







    _______________________________________________________
File Attachments:

Bash script to illustrate the observation

Name: set-e-handler.sh               Size: 224B
    <https://file.savannah.gnu.org/file/set-e-handler.sh?file_id=57786>



    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-617ea5df01d753693c126fee1cb8b23ce917ea5d.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?67679>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to