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

Harald van Dijk harald at gigawatt.nl
Fri Aug 20 14:36:27 UTC 2021


On 20/08/2021 15:14, Roberto A. Foglietta wrote:
> Il giorno ven 20 ago 2021 alle ore 15:21 Harald van Dijk 
> <harald at gigawatt.nl <mailto:harald at gigawatt.nl>> ha scritto:
>     Hi,
> 
>     Please note the "when an outer context has already set LINENO"
>     qualification :) busybox does have one call to evalstring() when no
>     outer context has set LINENO to be preserved (and a prior context might
>     have set it to an unrelated value that should be discarded): that
>     happens when processing the command string supplied with the -c command
>     line option. In that case, it is probably best to let LINENO start at 1
>     from the start of the command string like busybox ash currently does.
> 
> 
> Hi,
> 
>   it is a matter of convention: external commands strings could have 
> lineno 0 or 1.
>   The patch attached simply changes the initialisation value. As you 
> wish or like.
>   IMHO, the value 0 informs that LINENO has no meaning: it is more 
> informative.

That isn't what happens though, you don't guarantee that LINENO will be 
0 to inform that it has no meaning. It will be incremented in multi-line 
command strings, and as I wrote, an earlier context may have set LINENO 
to an unrelated value. With your earlier patches, with 'make defconfig', 
I see:

   ./busybox ash -c 'echo LINENO=$LINENO
   echo LINENO=$LINENO'
   0
   1
   cat >shrc <<EOF
   :
   :
   :
   EOF
   ENV=shrc ./busybox ash -ic 'echo LINENO=$LINENO'
   3

With your last patch, that first case is changed to print 1 / 2, but the 
second case still prints 3. I can understand outputting 0 / 0 for the 
first case and 0 for the second case, and I can understand (and would 
personally prefer) outputting 1 / 2 for the first case and 1 for the 
second case. Outputting 3 for the second case seems wrong.


More information about the busybox mailing list