[PATCH] shell script error management in ash (set of 6 patches)

Harald van Dijk harald at gigawatt.nl
Fri Aug 20 12:05:53 UTC 2021


Hi,

Replying to the new thread as requested.

About the global LINENO: having thought about it more, I don't think it 
makes sense to special-case trap actions. This is something that should 
be done for all evalstring() calls that are performed when an outer 
context has already set LINENO. In the busybox version of ash, there is 
only one other such case: the eval command. So please consider:

   #!/bin/busybox ash
   echo LINENO=$LINENO
   eval 'echo LINENO=$LINENO; set -o invalid'

This prints

   LINENO=2
   LINENO=1
   ./test.sh: set: line 1: illegal option -o invalid

That's not ideal. The line number 1 is defensible, but it's not line 1 
of ./test.sh as gets printed. This would be better if it got printed 
either as line 1 of the eval string, or line 3 of the script (and LINENO 
updated to match).

In my experience, printing this as line 3 of the script is more useful. 
POSIX does not require any particular value in this case, so in my 
shell, I will update it to do just that. I'm finishing some testing and 
hope to push that later today. As with the earlier patch, if this would 
be useful for busybox, feel free to use it.

On 14/08/2021 17:14, Roberto A. Foglietta wrote:
> Hi all,
> 
>   I will send the whole six patches developed in these days with the 
> test suite in a tarball.
> 
> busybox-1.33.1-1of6-add-trap-ERR-to-ash.patch
> busybox-1.33.1-2of6-trap-ERR-fix-global-LINENO.patch
> busybox-1.33.1-3of6-set-E-error-trace-added.patch
> busybox-1.33.1-4of6-global-FUNCNAME.patch
> busybox-1.33.1-5of6-multiline-trap-LINENO-bugfix.patch
> busybox-1.33.1-6of6-when-FUNCNAME-is-null-bugfix.patch
> 
>   The whole set enanches the shell script management in ash (compatible 
> with bash)
> 
>   Best regards,
> -- 
> Roberto A. Foglietta
> +39.349.33.30.697


More information about the busybox mailing list