On Mon, Jun 30, 2025 at 10:45 AM Greg Wooledge <g...@wooledge.org> wrote: > > On Mon, Jun 30, 2025 at 08:33:49 -0600, Stan Marsh wrote: > > It seems to me that there is never any need for $ in arithmetic contexts, > > so the > > obvious fix would be to just remove any $ found between (( and )). But > > from what I > > understand that is easier said than done. > > Unfortunately, that's not true. You need $ if you want to use any > special parameters in an arithmetic context, such as $# or $1.
I've done var="$(( ${BASH_REMATCH[NOW_START_CG]} + ${BASH_REMATCH[NOW_COUNT_CG]:-1} ))" where a line just matched against a regexp representing unified-format diff hunk headers, in which I'm using capturing groups to pull out the numbers. The hunk headers don't bother to say when there's only one line in the diff pre- or post-image part of the hunk. I've also done (( array[i] = ${array[i]-0} | BIT_MASK )) where I may or may not be setting array[i] for the first time. I know this wouldn't be necessary if I didn't use 'set -u'. All of this could probably be worked around in one way or another, but it looks a lot more natural if you don't have to.