On Sun, Oct 10, 2021 at 1:48 PM bm1les <bm1...@protonmail.com> wrote:

> Exactly my point. Even if the circumstances were contrived, I think it
> would good to fix it just for the sake of correctness.
>

Sure, knowing what circumstances could cause a problem assists in
achieving correctness.



> The issue is actually a pattern I found not only in /etc/netstart but also
> in /etc/rc. (( )) cannot deal with an empty result yet it sometimes
> includes calls to sysctl which apparently can return an empty string in
> some cases.
>
> So options are:
>
> 1. ensure that sysctl always returns a number where it is expected
> 2. work around the issue by using /bin/[ in place of or in addition to,
> the arithmetic expression (depending on the expression being tested), so
> that whatever returns empty string can be tested instead of blowing up.
>

3. use syntax with works when the expansion is empty, such as
      (( $(sysctl blah) + 0 != 0 ))

   which is unary plus when it's empty, or
       (( $(sysctl blah)0 != 0 ))

   which multiplies the value by 10 when not empty and is zero when it's
empty.


Philip Guenther


(Per POSIX rules, any arithmetic expression is effectively evaluated in
double-quotes.  If you follow the spec from there, you can work out that if
an arithmetic expression that directly** contains double-quotes parses
correctly, then it must also parse correctly with the double-quotes
removed; adding double-quotes can't fix an arithmetic expression.  The
reverse is not true: adding double-quotes can break the parsing.  ** i.e.,
not counting quotes inside a nested parameter expansion or command
substitution.)

Reply via email to