Essentials of Bash Scripting: Using Loops
Oct 22, 2010, 13:04 (0 Talkback[s])
(Other stories by Joe 'Zonker' Brockmeier)
Re-Imagining Linux Platforms to Meet the Needs of Cloud Service Providers
"An essential rule of system administration: If you need to do
something often, try to write a script to do it for you. If you
need to do something several times within a script, you'll need to
be able to use loop statements to repeat something until done. With
GNU Bash, you'll do this with for, while, and until statements.
"If you've done any programming, you're probably familiar with
these statements already. If you're like me, and were introduced to
bash scripting without benefit of a programming background, they
might not be quite so obvious. Let's start by explaining the
differences between the statements, and then move on to
"The for loop is used to iterate through an action until done.
Let's say you have a directory full of images that you want to
convert from one format to another. You could use a for loop and
ImageMagick's convert (or another program) to convert JPEG images
into PNG format, for instance. Or create a script to take a
directory full of MP3s or WAV files and convert to Ogg Vorbis."