I want to assign a variable based upon the modulo of another variable (subject number, in this case), getting a number (representing subject condition) which cycles over N conditions.
In other words, I want something very similar to the modular function a%n
, but for full multiples of n
I want to return n
, rather than 0
.
I think the easiest way to do this is with an or conditional, such that if the mod function returns 0, N will be returned instead, but I can't get the syntax to work.
subj=4
list=$((subj%4)) || 4
echo $list
just returns the result of subj%4
, and ignores the conditional, while replacing ||
with -o
fails.
If I try and use brackets around the whole thing, I just get a binary output of the conditional test.
What am I missing?