[Top][All Lists]

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

Re: Function declarations produce no trace nor trigger debug trap while

From: Chet Ramey
Subject: Re: Function declarations produce no trace nor trigger debug trap while having side effects
Date: Thu, 27 Oct 2022 17:26:46 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.0

On 10/27/22 11:33 AM, Erik Adelbert wrote:

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

We have found that 
[https://www.gnu.org/software/bash/manual/bash.html#Shell-Functions shell 
function] _declarations_:
0 do not emit trace output
0 do not call DEBUG trap
0 modify $?

Unless we have missed the related documentation,

This is from the man page for `set':

      -x      After  expanding  each simple command, for command, case
              command, select command, or arithmetic for command, dis-
              play  the expanded value of PS4, followed by the command
              and its expanded arguments or associated word list.

No shell includes function definitions in `set -x' output, and I don't
see how doing so adds value.

And for `trap':

      If a sigspec is EXIT (0) the command arg  is  executed  on  exit
      from  the shell.  If a sigspec is DEBUG, the command arg is exe-
      cuted before every simple command, for  command,  case  command,
      select  command,  every  arithmetic  for command, and before the
      first command executes in a shell function  (see  SHELL  GRAMMAR
      above).   Refer to the description of the extdebug option to the
      shopt builtin for details of its effect on the DEBUG trap.  If a
      sigspec is RETURN, the command arg is executed each time a shell
      function or a script executed with the . or source builtins fin-
      ishes executing.

A function definition is a command itself. This is from the man page in
the `Shell Function Definitions' section:

"The exit status of a function definition  is  zero
 unless  a  syntax  error  occurs or a readonly function with the
 same name already exists."

we believe the current semantic to be at least unclear and would like to see either:
0 the DEBUG trap called _before_ any function declaration (preferred)

While calling the DEBUG trap before certain compound commands has value, I
don't think that function definition commands rise to that level.

0 or function declarations preserving $? as they are not commands appearing in 
trace and DEBUG (has cons)

They are required to exit with status 0.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

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