[Ilugc] [TIP] shell variables

  • From: l.mohanphy@xxxxxxxxx (Mohan L)
  • Date: Thu, 22 Dec 2011 12:34:46 +0530

On Thu, Dec 22, 2011 at 12:11 AM, ashwin kesavan <ashwin.chn at gmail.com>wrote:

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


Ashwin,

Please don't see it as simple if construct.  There are lot of attention
required while used to evaluate expressions .

See the deff here : http://mywiki.wooledge.org/BashFAQ/031

Thanks & Rg
Mohan L

Other related posts: