Re: shell script error management in busybox ash

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

 



On Wed, Sep 15, 2021 at 10:16 PM Harald van Dijk <harald@xxxxxxxxxxx> wrote:
> >>> Yes, _this_ is the problem we are having.
> >>>
> >>> E.g. $FUNCNAME in EXIT trap needs to be current function's name.
> >>
> >> Important to also mention that although FUNCNAME is not part of POSIX,
> >> and there is no spec to compare to, in bash and ksh it does not behave
> >> that way
> >
> > In my testing, it does.
> >
> >> so you're talking about implementing FUNCNAME in a way that is
> >> incompatible with existing shells.
> >
> > Try this in bash:
> >
> >    trap 'echo trap:$FUNCNAME' EXIT
> >    f() { exit; }
> >    f
> >
> > I'm getting:
> >    trap:f
>
> For bash, it depends on how the shell is invoked. When bash reads
> commands from stdin, it prints trap:f. When bash is called with that
> exact same script passed as -c, it prints trap:. There may be a more
> specific option that can control this.

Indeed. In -c, it prints "trap:"

In a script, it prints "trap:f"

Looks quite inconsistent.

Well, in this case I'd fall back to "what would be the most _useful_
behavior". Losing information in which function "exit" was is less useful.
I prefer passing it to EXIT trap.



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux