Skip to main content
Post Undeleted by ChatterOne
added 232 characters in body
Source Link
ChatterOne
  • 2.9k
  • 12
  • 18

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 

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 

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 
added 28 characters in body
Source Link
ChatterOne
  • 2.9k
  • 12
  • 18

As I said in the (now deleted) comment, I don't think thisthat 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 

As I said in the comment, I don't think this is really a "bash" solution.

In pure bash you can do something like this:

#!/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 

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 
Post Deleted by ChatterOne
Source Link
ChatterOne
  • 2.9k
  • 12
  • 18

As I said in the comment, I don't think this is really a "bash" solution.

In pure bash you can do something like this:

#!/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