Sponsored Content
Top Forums Shell Programming and Scripting Unix Korn Shell Array Issue (SunOS) Post 302097114 by Andrek on Tuesday 21st of November 2006 07:05:46 PM
Old 11-21-2006
Ok I'll do my best...

while [ $start -lt ${#lsarry[*]} ]
Simple while loop.
It keeps looping until the var $start is lessthan the total number of elements in the arry.
eg ${#lsarry[*]} would be equall to 4 if
the array is made up as follows "A B C D"
The # indicates to give the "count" of the elements in the arry and the "*" simply indicats ALL the elements.... (I guess its like a wild card...ie ls *-> which list every thing)

the "-d" is a test for a directory. Does it mean "IF 'D' = ArrayValue?" NO.

Do a man on "test" and you will see all the options. UNIX will "test" the input and return true if the path/to/target is a directory or false if not. How is it being inerpreted?

if [ -d ${lsarry[$start]} ] How is the code being interpreted? - as you know $start is increased by 1 each loop so the "next" element in the arry is placed into the "test" statment and evaluated....ie ${lsarry[1], ${lsarry[2], etc....

you can run the script with full debug on to see whats happening by either...
1) add set -x to the second line ....or
2) # sh -x {scriptname}

Hope this helps.

PS do a man on sh-bourne or man on ksh and near the bottom it talks about arrays and what "#" etc means....

Have fun :-)
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Oracle To Korn Shell Array

I'm attempting to populate an array in ksh using the following command: set -A $(SELECT_INVOICE | sed '/^$/d') SELECT_INVOICE is a function that executes the SQL query. Problem: Some of the invoice numbers have alpha characters with spaces(example: OVEN MICRO). The Korn shell is treating... (1 Reply)
Discussion started by: kdst
1 Replies

2. Shell Programming and Scripting

korn shell array?

I read it is possible to provide values for an array with the -A option to the read statement; however, I have not been able to get this to work. When I execute a script with the -A option to the read statement, the shell complains that it is an illegal option. If this works, can someone provide... (5 Replies)
Discussion started by: cstovall
5 Replies

3. Shell Programming and Scripting

I can't decalar an array in my korn shell script

I have a script that contains #!/usr/bin/ksh set -A X 'hallo' 'world' echo ${X} echo ${X} when I execute it I get an errror message sh ./test.ksh ./test.ksh: -A: bad option(s) but if I do this at the command prompt I am able to create it set -A myarray '1' '2' '3' echo ${myarray}... (4 Replies)
Discussion started by: zilla30066
4 Replies

4. Shell Programming and Scripting

Could someone give me an example of awk accessing array defined in Korn Shell?

As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies

5. Shell Programming and Scripting

korn shell .kshrc in sunos

Hi, My login shell is c shell I have a line in .cshrc like setenv a 1000 I have a line in .profile like ENV=$HOME/.kshrc export ENV and in my .kshrc a=10 export a I wrote one korn script #!/bin/ksh echo $a (3 Replies)
Discussion started by: shahnazurs
3 Replies

6. Shell Programming and Scripting

need help with korn shell array

I have a korn shell script that reads a file with just one column in the file. If the file has more than 5 entries it is split using split -5. This means that is we have 15 entries I will end up with 3 files with 5 entries/lines in each and if I have 23 entries I will end up with 5 files with the... (2 Replies)
Discussion started by: kieranfoley
2 Replies

7. Shell Programming and Scripting

Generate array name at run time Korn shell

Hi, I am trying to define number of array based on constant derived during execution phase of a script. Here is what i am trying.. #First Part, Get LUN input from User lun_count=4 count=0 set -A my_lun while : do while ]; do read L?"Enter Lun "$count" Number:" ... (2 Replies)
Discussion started by: harris2107
2 Replies

8. Shell Programming and Scripting

Korn Shell Array maximum value less than other value

I have a text file with several key words that I am trying to isolate. I have grepped for the unknowns in the text file, but each unknown has a corresponding location. I have created an array that holds all the unknowns and another array that holds all of the locations and compares them based on... (12 Replies)
Discussion started by: ther2000
12 Replies

9. Shell Programming and Scripting

'*' vs. '@' in Korn Shell Array Variables

In order to use the shellcurses functions described at: Shell Curses function library I am learning about ksh, which has arrays. My trusty Kochan & Wood book says that for any Korn Shell array AR : ${AR } expands to all the defined array elements, and ${#AR } expands to the number... (3 Replies)
Discussion started by: Clovis_Sangrail
3 Replies

10. Shell Programming and Scripting

How to append to array within conditional block in ksh/korn shell?

Hi, I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement. #!/bin/ksh echo "---------------------------------------------------" set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Discussion started by: sanzee007
2 Replies
for(n)							       Tcl Built-In Commands							    for(n)

__________________________________________________________________________________________________________________________________________________

NAME
for - 'For' loop SYNOPSIS
for start test next body _________________________________________________________________ DESCRIPTION
For is a looping command, similar in structure to the C for statement. The start, next, and body arguments must be Tcl command strings, and test is an expression string. The for command first invokes the Tcl interpreter to execute start. Then it repeatedly evaluates test as an expression; if the result is non-zero it invokes the Tcl interpreter on body, then invokes the Tcl interpreter on next, then repeats the loop. The command terminates when test evaluates to 0. If a continue command is invoked within body then any remaining commands in the current execution of body are skipped; processing continues by invoking the Tcl interpreter on next, then evaluating test, and so on. If a break command is invoked within body or next, then the for command will return immediately. The operation of break and continue are similar to the corresponding statements in C. For returns an empty string. Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the for command starts execut- ing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iter- ation), so changes in the variables will be visible. See below for an example: EXAMPLES
Print a line for each of the integers from 0 to 10: for {set x 0} {$x<10} {incr x} { puts "x is $x" } Either loop infinitely or not at all because the expression being evaluated is actually the constant, or even generate an error! The actual behaviour will depend on whether the variable x exists before the for command is run and whether its value is a value that is less than or greater than/equal to ten, and this is because the expression will be substituted before the for command is executed. for {set x 0} $x<10 {incr x} { puts "x is $x" } Print out the powers of two from 1 to 1024: for {set x 1} {$x<=1024} {set x [expr {$x * 2}]} { puts "x is $x" } SEE ALSO
break, continue, foreach, while KEYWORDS
for, iteration, looping Tcl for(n)
All times are GMT -4. The time now is 02:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy