[PATCH] adding the trap ERR feature

Harald van Dijk harald at gigawatt.nl
Sat Aug 14 12:28:55 UTC 2021


Hi,

On 13/08/2021 23:45, Roberto A. Foglietta wrote:
>   Hi Harald, thank you for having shared your point of view.
> 
>   I agree that POSIX specs are important but not mandatory.
>   Moreover they not always very specific like in this case.
> 
>   Obviously for the functions defined elsewhere it might be different.
>   I prepared a test but feel free to improve it. Here the results:

The case that I was thinking of is functions defined in an interactive 
shell, that's where it doesn't make sense, in my opinion, to count how 
many lines have been entered in that session before the function was 
defined, and where I think POSIX did the right thing in requiring LINENO 
to be counted from the start of the function in that case.

Other than that, to me personally, your expected results look reasonable 
enough. LINENO in trap handlers is something other shells do 
differently, but it's not consistent across shells, it's not covered by 
the standard, and it's not something that I would expect existing 
scripts to rely on.

One case not covered in your tests is multi-line trap handlers. If 
LINENO in a trap handler, whether ERR, EXIT, or anything else, is 
supposed to refer to the point where it activated, then I think it 
should do so all throughout the trap handler. Correct me if I am 
misreading your patches, but I think that is not what you are doing, I 
think you only start counting at the point where it activated. Is that 
correct? If so, is that the behaviour you are after?

Cheers,
Harald van Dijk


More information about the busybox mailing list