When I first learned about Linux in the 90’s, I read that it was possible to even write your own commands to use at the command line. Later I learned about bash scripting, and it wasn’t long before I needed to learn how to loop in bash. Looping in bash is one of the fundamental building blocks of bash programming. It isn’t hard to do at all and is worth learning. The main reason to learn looping in bash is to handle doing the same thing over and over again. They’re easy to do even at the command line. Please follow along as we look a couple of basic examples, and how you can expand on them.
http://www.tidbitsfortechs.com/2014/10/looping-in-bash/
(Score: 3, Informative) by PizzaRollPlinkett on Sunday October 12 2014, @03:42PM
I recommend O'Reilly's "Classic Shell Scripting" book. I usually have to do bash scripting every few years when someone needs a shell script for some reason and doesn't want a Perl or Python program. If you're used to real programming languages, sh and bash are badly designed and confusing and I never really remember them. (I don't care what you say about Perl, bash has words spelled backwards - did Zatanna design it? The syntax looks like a junk drawer of random stuff taken from every programming language in the 70s. Even REXX makes more sense, and some of the commands have open parens without close parens.) The first thing I do is pull down this book and try to read up on what I need to know.
I have a sample somewhere of looping through an array that I always dig up because it's not obvious. But it's not the hardest thing to remember. There's a "for scalar in array" construct, but the hard part for me has always been getting something into an array.
Anyhow, bugs or not, bash is harmful to my brain and I try to use a real programming language for any script I possibly can.
[!si annataZ ohw wonk uoy epoh I]
(E-mail me if you want a pizza roll!)
(Score: 0) by Anonymous Coward on Sunday October 12 2014, @04:10PM
O'Reilly's
You might want to read this http://thebaffler.com/articles/the-meme-hustler [thebaffler.com]
(Score: 2, Interesting) by hendrikboom on Sunday October 12 2014, @06:31PM
The backwards words are an Algol 68 legacy, and are close brackets that match the correcponding forward-spelled words. The variety of brackets makes it easy to detect, diagnose, and correct missing brackets. I contrast this with C's '}', Pascal's ubiquitous 'END' and Lisp's even more irritating ')'.
-- hendrik
(Score: 1) by Qzukk on Sunday October 12 2014, @09:56PM
Rather than thinking of it as "in array" think of it as "in list" where list is a string of things separated by whatever character(s) in $IFS