Advanced

How to use for/while/until loop in bash

Posted by bob on · 4 comments
Xmodulo; By Dan Nanni
Mail this story
Print this story

Undoubtedly the most useful feature of bash scripting is loop control. In any imperative programming language like bash, loop statements are commonly used along with conditional statements to perform repetitive tasks. In case of bash, three different types of loop statements are available: for, while and until. This tutorial demonstrates how to use for, while and until loops in bash using detailed examples.

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Developer, Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (4)

Bash and the native Unix/Linux tools (sed, awk, etc.) make it easy to process text and files. I turn to Ruby when something needs to be cross-platform, but many things involving editing text and writing and processing files is easier in Bash.
It's definitely worth learning how to manipulate text and files in a scripting language like Ruby, Python or Perl, but often a Bash script is faster to create.
I fell in love with Ruby several years ago and for a while used it almost exclusively as my scripting language of choice. Now I've migrated to Python mainly because of the vast library support encircling that language.
I've used Perl and Python on occasion, but never Ruby. As Steven notes, there are many simple editing tasks that can be handled in Bash without utilizing other languages. For some simple tasks, you don't need any other tools; other times it is worth calling another tool from Bash; still, unless it is a complex task, doing it in Bash is simpler and often easier.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post