Thanks drl,
The Perl document says:
Quote:
If $n is positive, then $m % $n is $m minus the largest multiple of $n less than or equal to $m.
which covers this case and the result should be positive or "matching the divisor". As you point out, the Wikipedia table shows BASH gives the same sign as the dividend and ASH seems to be the same.
My application was for a circular counter: given a value
m, in the range 0..(
size-1), the next entry is
next=$(( ($
m+1) % $
size)) while the previous should be
prev=$(( ($
m-1) % $
size) but that gives -1 for $
m=0. The workaround is to use
prev=$(( ($
m+$
size-1) % $
size) which should work on any shell.
Thanks for all the detailed replies, I've picked up quite a bit on the syntax from this thread as well as resolving the question.