i is a variable, as in basic:
for i = 1 to 10 : next i

c/perl/java:
for(i=1; i<=10; i++) ;

bash
for (( i=1; i<=10; i++ )) ; do echo $i ; done

or when we are using text instead of integers, i is a word seperated by
spaces.

integers="1 2 3 4 5 6 7 8 9 10"
for i in $integers ; do
        printf "%2d\n" $i
done

 1
 2
 3
 4
 5
 6 
 7
 8
 9
10


similarly you can say:

for justin in `date` ; do
        echo $justin
done

Tue
Aug
14
13:15:40
2001

i is merely a very common convention for simple for loops across many
languages.

The seperator ' ' (space) is setable.  From `man bash`:

 IFS    The  Internal Field Separator that is used for word
        splitting after expansion and to split  lines  into
        words  with  the read builtin command.  The default
        value is ``<space><tab><newline>''.

-----Original Message-----
From: Justin Bengtson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 14, 2001 1:02 PM
To: '[EMAIL PROTECTED]'
Subject: [EUG-LUG:2195] RE: BASH question


mos' definitely.  what exactly does "i" represent?  from what i'm reading
here (and what cory told me in-office) it seems to be a word between spaces.
if so, that's exactly what i'm looking for.

the expression below doesn't look complete...  "for i in $(DATE); do"
should there be a "each" in the statement?  or does the statement only act
on the first "i"?  or does it not need an "each" because it's implied?

sorry, but i'm confrused here.  the man pages for BASH are horrible...

and thanks for the help!

-----Original Message-----
From: Jacob Meuser [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 14, 2001 1:06 PM
To: [EMAIL PROTECTED]
Subject: [EUG-LUG:2193] RE: BASH question


On Tue, Aug 14, 2001 at 11:59:52AM -0700, Cory Petkovsek wrote:
> var=`date` ; echo $var
> Tue Aug 14 11:58:46  2001
> 
> Multiple results?  Please define.
> 
Maybe he's thinking of something like this: (not tested with bash, but
should work)

#!/bin/sh

DATE=`date`

for i in ${DATE}; do
    case ${i} in
      Mon) echo "It's Monday" ;;
      Tue) echo "It's Tuesday" ;;
      PST) echo "Pacific Standard Time" ;;
      PDT) echo "Daylight savings in effect" ;;
    esac 
done

-- 
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>

Reply via email to