[Ilugc] [TIP] shell variables

  • From: ashwin.chn@xxxxxxxxx (ashwin kesavan)
  • Date: Thu, 22 Dec 2011 00:11:01 +0530

On 20 December 2011 07:36, Girish Venkatachalam
<girishvenkatachalam at gmail.com> wrote:
....

Now, let us look at a simple while loop with counting. As I said, for
is only an iterator. It is not a
?real loop like while.

$ cat i.sh
let i=100

while [ $i -gt 0 ];
do
? ? ? ?echo $i
? ? ? ?let i--
done

This is a nice way to iterate with a while loop.

I repeat.

for takes a list of values beforehand and runs the loop thro' them
like list of files or
?list of numbers or list of strings or a combination.

while has a condition like in C and runs the loop infinitely till the
condition is true.


Girish ,

Instead of talking about if and while in shell, which is present in
every programming language ( Anyone with some programming knowledge
should be able to figure this out in no time), why not talk about
regular expression and sed and awk.  which are more intresting than
looping constructs.


--ashwin

Other related posts: