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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5413 invoked from network); 28 Jul 2021 05:01:41 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Jul 2021 05:01:41 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1627448501; b=X3sX6m4vWRc6vogZTFLxpOJy5EtRrtdfZwa98ren+stif5aRXMmxdKTzJOCNYFw7M41mpTY8Ly FEll6NhTzyDH9PyZycdYEN3jIZtd9eLMVySRRgNEpnTgpKSC3QUwB78Zks9uj9U/1la/TOe6ro uxfF0sJ+t9L0YiNk6hXx0ivsP4pXUmwV77KmWeT8Pc3d9JzeVYBV3HM3B7Y1rB3gQrS7GA4kvc tMCp2XXi1U6/nrDRfYEsXo/8SzVj28YUl60J1YljlTvdcLVErvYwftZN7Ihot845geb9nAGl7N RG5itqY5cyj/PEV0Z7QYBpTClk7pufhlQjOZJX0sTHWAHQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f180.google.com) smtp.remote-ip=209.85.219.180; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1627448501; bh=WjyE9Qc9SBJbjHGzf+FChBR72qREgiuDhn4rM7kB2GA=; 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=MVeINzLwb/S5GdFXEaAEkdhsivw9XXl4AVLZdjfT+mxSRlv/ooS1vJ6z3gwjamdnfGIwgV5vYg fOvK5YWuQT7Z5cEEHT69qfa3R1NDvUJf9wvtS7TbSzkcwGBJH/Bu7tseH++r3+494QvOxAihXA A71LznTvAMIyeJXiRvODoo9gklISGuuwfcFrnUf7yC29dqCRHvFvsXhxLT8R0SJ6NMMx9nw9lh oXVcVeAT3TDXz3Rg6sLINFhqZ7S9gUoffdXBatmebzEG9kOnRpaBsVLVfHJ6Wlav4LNJrWG5HU lu7AQBlFQsP48PXjIS5yW1rP/TVmbJceZxxx/4t63/R4Cw==; 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=lDGJa4L+Slv/gOMpmDu0qMmwlI4LAqSbPrSVpb8USfA=; b=zUEHu429Nku0N9TIfy35hvbEbB dy2OCy0c8wpbEkk+0hezUENMrOkDDFIIbXKGq4niL9HGqSQmAOMpHe8vf37ZzUuDbHlL2xOqrGQUq g1nrtaoiveIfhN3CaUcJ0mygQwvocCDgahATXarSqmuyxbfgUt3qsc2oYqalJKnWNWjx02nOjk3Nc fno29v7wHEtLpXbUYkY7H6PbtM+KRzCqmCzmLedmwlc2AMd5GqpwwNJozG6Fbb5IlHBL8fenm8VAM jrwLW8Jdy9jvrPCQnXiug/Q41j4oBAFwkqytKwQoKQAuw+cnQ72eP4j2UWazxkRQbjAA7OuIlgd5Q GgprTDJQ==; Received: from authenticated user by zero.zsh.org with local id 1m8bhL-000ARy-G3; Wed, 28 Jul 2021 05:01:39 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f180.google.com) smtp.remote-ip=209.85.219.180; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yb1-f180.google.com ([209.85.219.180]:41757) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1m8bgD-0009h6-CV; Wed, 28 Jul 2021 05:00:31 +0000 Received: by mail-yb1-f180.google.com with SMTP id z18so1842489ybg.8 for ; Tue, 27 Jul 2021 22:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lDGJa4L+Slv/gOMpmDu0qMmwlI4LAqSbPrSVpb8USfA=; b=wCGqNpWUssgR1eMxjnNLQG0/RJov7XlErQ800BGqrvXn341hMfinz7ZmSqGISvyP05 jSU+a5pgtG7iSOTifQkPnlw8ju7mhzeVz8tmCXJcIIBgme5/oD06SCmd8m9djVTazypQ lVUXMw4/xeZWRbTBroNOVWeFCHdjemPrCeKf1QuwYbz52frFcY1HMb/oK+G9MB3mq6n9 us+UWTwAaLQz++TF3anu6bDPjDl/NvTbKj30vKesBfI01LavT2/gd9GgoVU8byi2gcun fgs7DyebMvoKXc2TLupqqAcVdtY85n0lWxvNHlb/M4lwHnreOt6sh8orc4FEzm6VbejU O+Rg== 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=lDGJa4L+Slv/gOMpmDu0qMmwlI4LAqSbPrSVpb8USfA=; b=nAC7CyBa9yd68viAygm12vGfAr8FtYSAm4ctBnql2iuae1U+5UWHg69EK8XNyhWzYK HXRckpws7JdDjjeDCeZaTmrZa1x38ljSfGyzYwhhCUIwyEULsPcs6yNhxrm3QBdypyMI NaWaToEt7otdl6R2sPF1uGjhd4Xbgu1tFolKMzKprfghY7uW8PbJLzTa1+Yj44vrkk+L 1ryT5GOTBqP7VkcOa6bin7lMgGCdMSyUp5jILIdvhbbL6k9BhP++wsKEEtB9X5ZukMlD e5UPTYzxrDlGTw0kOu+gPoPd9A3kPpT6vj7siuebC8LutYVCb7RgB+aGNQ09myvkiZ6r f6kQ== X-Gm-Message-State: AOAM531sJGIpJpXqmKtTOfP7HY5PYXGI82Xwzy+/Bs0adTdYnVjgqh38 jJU8N3aJoKlLIgFLCphCFAaPv0kMWMnBqR5nbbcfFw== X-Google-Smtp-Source: ABdhPJy3MOVCvuieF0ptb0YDnvc5+ZiSPAc5WEg5/wkJULAAC1aNR8KnBRqO8X+FjTeYrFRZE2tylH4wW9RWA6lVdi0= X-Received: by 2002:a25:e042:: with SMTP id x63mr21804314ybg.398.1627448428064; Tue, 27 Jul 2021 22:00:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Tue, 27 Jul 2021 22:00:17 -0700 Message-ID: Subject: Re: Differences between "TRAPERR()" and "trap foo ERR" To: Zach Riggle Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26821 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: 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.