Sleeping within nested for loops in bash -


i have pair of nested for loops in bash shell script.

i want pause script every 60 seconds when counter hits multiple of 50 "ticks" or iterations, put in modulo test:

counter=1 ((i=0; i<${#libraries[@]}; i++));     ((j=(i+1); j<${#libraries[@]}; j++));         # stuff...         if [ $counter%50 == 0 ];             sleep 60s         fi         counter=$[$counter+1]     done done 

this loop behaves erratically — specifically, script not pause every 50 iterations, staggers , skips or otherwise not appear triggering expected sleep call correctly.

whatever put # stuff... script not pause expected, behaves in same erratic way. can comment out — same behavior.

the ${#libraries[@]} stuff array of file paths.

does sleep not work inside loops, or not using correctly? there alternative way pause script without breaking out nested loops separate wrapper scripts?

i think test wrong. try instead :

if (( counter % 50 == 0 )) 

the $counter%50 part never expand 0, test fail, , sleep never executed. % modulo operator requires arithmetic context, standard test command not provide, double parentheses will.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -