You might use a loop like these proven beneath to run by the letters of the alphabet or a sequence of numbers.
$ for x in a..z do echo $x performed $ for x in 1..11; do echo $x; performed
The for command beneath would show calendars for the final three months of the present yr.
$ yr=`date +%Y`; for month in 10..12; do cal $month $yr; performed
The script beneath loops by all of the months of the yr.
$ for month in `locale mon | sed 's/;/ /g'`; do echo $month; performed January February March April Might June July August September October November December
Utilizing whereas loops
Whereas loops preserve looping so long as the situation that they’re set as much as monitor is true. Right here’s an instance:
#!/bin/bash n=1 whereas [ $n -le 4 ] do echo $n ((n++)) performed
The script above increments and shows the worth of $n so long as it’s lower than or equal to 4. You will get some time loop to run eternally (i.e., till the system crashes, you sign off, or somebody kills your script) utilizing “whereas true” as proven beneath. The sleep command ensures that it doesn’t run 1000’s of occasions earlier than you may have an opportunity to cease it.
#!/bin/bash whereas true do echo -n "Nonetheless operating at " date sleep 10 performed
The script beneath will run so long as the consumer who it’s ready for has not but logged into the system. This may be useful if you’re ready for a co-worker to deal with an issue earlier than you’ll be able to transfer forward along with your job. It checks as soon as a minute to see if the consumer has logged in but.