From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5930 invoked from network); 28 Jul 2021 05:06:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Jul 2021 05:06:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1627448762; b=cGYA3GfLfYrVarMUBM543JQ8oLEghVeCDFPxKu8xMdLGMGG35Fr2glolH4CB73p+06WOGpoMTh C6ONJ/fyJpA5/6uWes17qVXqBXN4q9uo6noSP67sGkCcUVxMNJEdOvKx8cwriPWIWP9tbnHne5 Pp1MN3nmPN7LpPepqh4jhHzPw3+QtHls+s/EFZauwJa4dndzImA7Ts/EqRr9a6wcvpLTMjW5q8 Lk+aJOjF4YTxhwXvMlZmbbStyqYi3gmuggDXdgK4TZQwmUFaD74iwANfDJxaA826aGW2f+Lyzq 5cKqJChSnWv1xaB/l1p/eiNRklfvMkCczV3dOlwVZ5hcww==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wm1-f44.google.com) smtp.remote-ip=209.85.128.44; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1627448762; bh=9ay3Fgfg/gAvMqCl6z4kKLuF574n+GF+Fz86DRvmAUE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=l430T9StjiLzGeV49XjGQilibo1bJcsYJuTVi3NNvsmPFAEEySkHNuOZ7c8c8M+9E8M1WfG6tb WJAVvxRR/U5bhGkybaH2rIPqA2937Vs29/FhI4zCk9WDKdaMJm5QqN+HD5+s/pL+wGrepW4ZqB p57uyN0E8lpLWmgeJ59dfsGNcGgzxrancI9lDi1C9P3fRxQQgRDRg3laQW65xEnTjwFxLO9PF9 XNQKslKkiXITbiDQbS7qPoilUj3PRlEhjKwC43dqGhXQdKUQjnNqBaeCN2XSkrrf6CHUnWxcH8 k1m+wnPa7HHcNuBrg71WuFZUua5lwTJmNSWVLYtH32c15g==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Kktg6nYqaftu81+XMqSSuKh5OK4u4ez0bc6eRLYg38U=; b=mc0lsWbDvQZ+oPdOxLI0Oggas1 MUnDgme8ySxPPBg5EaqJktWe+98YG2sY+qxQZztU/DZWVMTp29AObTpGnQ5G8Y6ZdhGko9M5T8dle m1rD69abZy6bo78B05ZifgX/0MgDQVEYywHTrdNpVvqCmoE/Qr2d+1Joc8ntQhHcdaYUL9ga0OU0t 9y+TulkhYL6JsZhJmGpMBlnIWC/jQXEW2y2iJB/kJR4EU7cQ2OQcUbrlPixXxpEXbBc04w+4tEUAv kENqJG2xydf4RVstJknmwqLyoN8bxGt22XBo1V3WEcKaTyJbzkBC26QZb3cdDne0E2ZfQA5Egm5fo MtvnTpKQ==; Received: from authenticated user by zero.zsh.org with local id 1m8bla-000BnV-Ij; Wed, 28 Jul 2021 05:06:02 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wm1-f44.google.com) smtp.remote-ip=209.85.128.44; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wm1-f44.google.com ([209.85.128.44]:38469) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1m8bkd-000B2P-1Z; Wed, 28 Jul 2021 05:05:03 +0000 Received: by mail-wm1-f44.google.com with SMTP id o5-20020a1c4d050000b02901fc3a62af78so3374854wmh.3 for ; Tue, 27 Jul 2021 22:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Kktg6nYqaftu81+XMqSSuKh5OK4u4ez0bc6eRLYg38U=; b=MV+S7XdO9jtjlAVwgQlDs9G71m7YyqH1QCpcR6YUXZNlzJr+If9HGQS13zgZyWEEMG g0uWi+ZPPFtwrKQTHdELoV5ksMtZhWlvRfGh7lSYfSKU17m9BG7rZYPa7TIluwWhcPyY ADOSWZxRS9wuk9CnB0KiHf0ciT28mENJPewSLzTMsRcwiTFKZ3hCHQlA84t14rZ2zC87 jjerdiraoFIIW7Wpsyqc+/q0xB9U0E8fU5NEvXY+E0vBw2UjpxFc6CwAXatMrKyOv3Mj 3QVUgeuprFqA+U58vpnefbZ02o0RhclAbQzthiZr/uCVygfiEA8YTd2n8B0yeWFS4i43 iXqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Kktg6nYqaftu81+XMqSSuKh5OK4u4ez0bc6eRLYg38U=; b=Bx/fg/RtzKoSkWymPE6o/PKREQyPBZGcCKXHSh5A9YCQW6HjSZelB9NQffpbeqn9Yt ReYz98BSxo8FUVBP/fYqP3tCC6GANPo86rFZDhb642HY/VmzEi34z4LliSWkpxJ/1m+R bLmRtseflUKIZ+D5tpTKVBXa0dxjPrw6XmFDjwamxGpp7fmN9NbZ1IDkfBTiONivz075 v5LreS8vh00yb0ObqzCp5uUbG7NLmBrZ7Qr1jqgpegfcFY3dPzf8annM0B6wgKM5IS3u x3owiIh5pWcxsDO38tQTDdRyp1TSuXy0PlRVvxDUgMgmMo30BiMK4ijqAPG4UU6cnZn7 7Ldg== X-Gm-Message-State: AOAM533l0BN23iwzzXE2rHrN1g+gxPuxLfzA2KseLE8mBoGRRktEpMpd iZINL5OC7H/eIkl7fOIAaq7q9+N2zGvqwHH2ANgCUms+Lak= X-Google-Smtp-Source: ABdhPJzjpGmtlJ9pXiuCa8c8ppg+82wAGkPhUpyVJQn4+kdMR1qGEdIO9IefxHSIhlP2Ho8jN9XLWmdnJ/sSXI2z7OA= X-Received: by 2002:a05:600c:4e8f:: with SMTP id f15mr25743491wmq.174.1627448702425; Tue, 27 Jul 2021 22:05:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Zach Riggle Date: Wed, 28 Jul 2021 00:04:51 -0500 Message-ID: Subject: Re: Differences between "TRAPERR()" and "trap foo ERR" To: Bart Schaefer Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26822 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Thanks for the quick response, Bart! > The signal number will be passed as the first parameter to the function. Wow, I am dense and poor at reading documentation. Thanks for pointing out the relevant portion to me. > The TRAPnal form and the argument it receives are a zsh extension. Welp, that explains the rest of it! > You might also read about the POSIX_TRAPS and LOCAL_TRAPS setopts. Thanks, I will definitely look up the docs for this. Humbled and appreciative, Zach Riggle On Wed, Jul 28, 2021 at 12:00 AM Bart Schaefer wrote: > > On Tue, Jul 27, 2021 at 8:47 PM Zach Riggle wrote: > > > > Overall, there are two observations. > > > > 1. The behavior that TRAPNAL will receive NAL as its first argument, > > where NAL corresponds to a the system-defined signal values (e.g. > > SIGSEGV == 11). The name for this signal can be gotten from > > ${signals[x+1]}. This should be documented. > > 9.3.2 Trap Functions: > > TRAPNAL > If defined and non-null, this function will be executed whenever > the shell catches a signal SIGNAL, where NAL is a signal name as > specified for the kill builtin. The signal number will be passed > as the first parameter to the function. > > > 2. This behavior does not expand to "trap func NAL" statements, even > > if we try to pass "$@" to some function. This seems like a bug. > > It's not a bug; it's the normal behavior of the "trap" in the shell > language. The TRAPnal form and the argument it receives are a zsh > extension. > > The "trap" builtin takes an arbitrary list of commands rather than a > function body. There is therefore no "argument list" where the signal > number can be passed. If you write > > trap 'echo in a trap' USR2 > functions > > you will see that there is no TRAPUSR2 function created. "unfunction > TRAPUSR2" removes the USR2 trap as a side-effect, but also complains > "no such hash table element". That's a bit of an oddity, but is in > part why the doc for the "trap" builtin says: > > Defining a trap under either name causes any trap under an > alternative name to be removed. However, it is recommended that > for consistency users stick exclusively to one name or another. > > Other distinctions considered important are also mentioned there: > > Note that traps defined with the trap builtin are slightly > different from those defined as 'TRAPNAL () { ... }', as the > latter have their own function environment (line numbers, local > variables, etc.) while the former use the environment of the > command in which they were called. For example, > > trap 'print $LINENO' DEBUG > > will print the line number of a command executed after it has run, > while > > TRAPDEBUG() { print $LINENO; } > > will always print the number zero. > > You might also read about the POSIX_TRAPS and LOCAL_TRAPS setopts.