bug-bash
[Top][All Lists]
Advanced

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

Debian bug #929178: wrong trap displayed inside functions


From: Gioele Barabucci
Subject: Debian bug #929178: wrong trap displayed inside functions
Date: Mon, 25 Mar 2024 16:45:41 +0100
User-agent: Mozilla Thunderbird

Hi, I'm forwarding a minor issue originally reported in <https://bugs.debian.org/929178>.

If a function does not set a trap, `trap` will output the command set by the caller. This is just a cosmetic issue, the right trap will be run at runtime.

To reproduce this issue:

    #!/bin/bash

    f1() { echo "trap in f1: $(trap)" >&2 ; }

    f2() {
        echo "trap in f2 (initial): $(trap)" >&2
        trap "/bin/echo f2" EXIT
        echo "trap in f2 (final): $(trap)" >&2
    }

    trap "/bin/echo main" EXIT

    echo "f1 output: <$(f1)>"
    echo "f2 output: <$(f2)>"

Output:

    trap in f1: trap -- '/bin/echo main' EXIT
    f1 output: <>
    trap in f2 (initial): trap -- '/bin/echo main' EXIT
    trap in f2 (final): trap -- '/bin/echo f2' EXIT
    f2 output: <f2>
    main

Regards,

--
Gioele Barabucci



reply via email to

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