Shell scripting - looping and counting
Counting to 100 using a for loop
Section titled “Counting to 100 using a for loop”#!/bin/sh
for (( i=1 ; ((i-100)) ; i=(($i+1)) ))do echo $idone;The 2nd expression in the for loop must evaluate to 0 so that the loop will finish. This looks a bit unnatural compared to normal programming languages. Instead, consider using a while loop.
Counting to 100 using a while loop
Section titled “Counting to 100 using a while loop”#!/bin/sh
i=1;while [[ i -le 100 ]] ;do echo $i; i=$((i+1));done;Running something every second
Section titled “Running something every second”while true; do sleep 1 echo print every seconddone