As I said in the (now deleted) comment, I don't think that is really a "bash" solution.
In pure bash you can do something like this, looping once:
#!/bin/bash COUNTER=0 TOTALSUM=0 A=0 while [ $COUNTER -lt 1000 ]; do let A=COUNTER%5 if [[ $A = 0 ]]; then let TOTALSUM=TOTALSUM+COUNTER else let A=COUNTER%3 if [[ $A = 0 ]]; then let TOTALSUM=TOTALSUM+COUNTER fi fi let COUNTER=COUNTER+1 done echo $TOTALSUM But if you want the "one-liner" version (which is not really one line after all):
for ((i = 0; i < 1000; i += 1)); do let A=i%5; let B=i%3; if [[ $A = 0 || $B = 0 ]]; then let TOTALSUM=TOTALSUM+i; fi; done; echo $TOTALSUM