explain while loop in ksh shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting explain while loop in ksh shell script
# 1  
Old 09-12-2011
explain while loop in ksh shell script

Code:
#!/bin/ksh
 
log[0]=ABCl
log[1]=EFG
log[2]=HIJ
 
i=0
while [ $i -lt 3 ]  <------ what is the meaning of ($i - lt 3)
do
   print ${log[$i]}
   (( i=i+1 ))
done


Last edited by vbe; 09-12-2011 at 10:33 AM.. Reason: Use code tags please
# 2  
Old 09-12-2011
Test that the value held in variable "i" (typically used for an index variable) is less than 3. Note that variable i is incremented at the end of the loop, increasing its value by 1. So, it loops 3 times and is used as the index of the array called "log", thus displaying its contents.

You could use (( $i < 3 )) which may make more sense?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with loop in ksh script

Hi, I am new to UNIX. I am working on a script where it takes the input and produces a desired output and it works fine for one instance. Input(One Instance): CREATE TABLE TAB1 ( COL1, COL2 ); CREATE UNIQUE INDEX XPKTAB1 ( COL1 )TAB1; Output: CREATE TABLE TAB1 ( COL1, COL2... (8 Replies)
Discussion started by: varun2327
8 Replies

2. Shell Programming and Scripting

please explain why this ksh echo deletes character

Please explain why this works. Am unable to find another definition for the '%', which would explain this behaviour: spaceLeft=`df -h /myPartition | tail -1` # output looks like: /dev/sda5 10G 1.2G 12G 29% / set -- $space #this deletes the trailing '%' sign, which is... (6 Replies)
Discussion started by: frododot
6 Replies

3. Shell Programming and Scripting

Explain this shell script code.

Hi i am new to shell script can any one please explain me the code below which is written for execution of python scripts which are located in same folder. please explain the code line by line ls *.py > xx while do read myline || break python $myline done<xx Thanks Mukthyar.... (1 Reply)
Discussion started by: mukthar1255
1 Replies

4. Shell Programming and Scripting

Aix .ksh for loop script.

Hi, I'm trying to write a for loop to run through a list of servers and for each server copy a file to a backup file. But I can't seem to get it to run through my server list. It work for individual servers, please see below. #!/bin/ksh SSH_USERID=khcuser webservers="server1 server2" ... (2 Replies)
Discussion started by: elmesy
2 Replies

5. Shell Programming and Scripting

Setting a variable in a while loop (.ksh script)

Hello Everyone, I'm still trying to grasp many concepts in .ksh scripting, one of them being variables inside loops. My problem is the following: * I'm trying to set a variable inside a while read loop to reuse it outside of said loop. My lines are the following :... (13 Replies)
Discussion started by: jimmy75_13
13 Replies

6. Shell Programming and Scripting

for loop in awk script using ksh

Guys, I am new in awk , I face problem while i try to use for loop in awk, I am using ksh, i am trying to set a for loop which runs as man times as the records in a file , the for loop like for(a=1;a<=5;a++) is working in my awk script but the one i need is not working :wall: for example ... (8 Replies)
Discussion started by: djahmed
8 Replies

7. Shell Programming and Scripting

please explain this sed shell script to remove C++ comments.

#! /bin/sed -nf # Remove C and C++ comments, by Brian Hiles (brian_hiles@rocketmail.com) # Sped up (and bugfixed to some extent) by Paolo Bonzini (bonzini@gnu.org) # Works its way through the line, copying to hold space the text up to the # first special character (/, ", '). The original... (1 Reply)
Discussion started by: Priyaranjan
1 Replies

8. Solaris

Pl explain the shell script code

if then ROLLBACK=1 ; elif then echo "Nothing to install!" ; echo "Exiting." ; exit 0; Plz explaing what is the ${1:-0} in if loop?:) (3 Replies)
Discussion started by: ysrikanth
3 Replies

9. Shell Programming and Scripting

explain me this shell script ...

currentSid=${TWO_TASK:-$ORACLE_SID} echo $currentSid this script returns value of ORACLE_SID but what i am not getting is what is ":-" doing ?? (1 Reply)
Discussion started by: zedex
1 Replies

10. Shell Programming and Scripting

Please explain read in a while loop

I have a script which tries to read input from a user for every value read from a file. The input file is #> more testfile TEST1 | D200 | 12345601 | | ABC company | m TEST2 | D201 | 12345602 | | ABC company | m The script test.sh is as follows while read line do read test?"Enter a... (5 Replies)
Discussion started by: jerardfjay
5 Replies
Login or Register to Ask a Question