That happens in the last loop. You are running loop variable i one too high for the array elements (i = 4; with elements only from 0 to 3). Try
in lieu of -le.
Run script with the xtrace (-x) option set to see what is going on.
You nailed it.
Thanks a lot.
I am a newbie.
------ Post updated at 01:51 PM ------
Thanks to you RudiC for the extra suggestion of using xtrace in troubleshooting. I'm grateful.
That was my first post here and I only joined yesterday.
$ errpt | more
IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION
3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR
B8113DD1 0802050205 T H fcs1 LINK ERROR
B8113DD1 0802050205 T H fcs1 LINK ERROR
3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR
B8113DD1 ... (0 Replies)
$ errpt | more
IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION
3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR
B8113DD1 0802050205 T H fcs1 LINK ERROR
B8113DD1 0802050205 T H fcs1 LINK ERROR
3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR
B8113DD1 ... (2 Replies)
Hello,
I'm brand new to this forum. I am working on my first Bash shell script. We were given an exercise to get ready for the real assignment. I could use some help.
The exercise is to "set two variables (i. e., file1 & file2) on the command line to the paths of the text files. We are to... (1 Reply)
Hi all, dummy here.... I have major errors on entering the shell. On login I get:
-bash: dircolors: command not found
-bash: tr: command not found
-bash: fgrep: command not found
-bash: grep: command not found
-bash: grep: command not found
-bash: id: command not found
-bash: [: =: unary... (12 Replies)
Guys,
I am trying to get unique numbers which i can use as a primary key in a table. I tried using the <seconds_since_epoch>.<hostname> combination but since more than one process can run on the same machine at the same time, this won't be unique either. Can anyone tell me another way to do... (2 Replies)
PHP question...
I have an SQL query that's pulled back user IDs as a set of columns. Rather than IDs, I want to use their names.
So I have an array of columns $col with values 1,7,3,12 etc and I've got an array $person with values "Fred", "Bert", "Tom" etc
So what I want to do is display the... (3 Replies)
if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Hello
I am using gfortran and I intended to do thiis:
Module variables
character(len=:), dimension(:), allocatable, array
end module variables
Sub test
use variables
integer (max_len)
max_len=len_trim("something here")
if(.not.allocated(array))... (1 Reply)
Dear All,
I created a new partition through "Integrated Virtualization Manager" but there have an error when I added a new disk to the partition. The disk already created without any issue,
Below error is to add the disk to the partition
An error occured while modifying the assignments... (5 Replies)
Discussion started by: lckdanny
5 Replies
LEARN ABOUT OSX
foreach
foreach(n) Tcl Built-In Commands foreach(n)
__________________________________________________________________________________________________________________________________________________NAME
foreach - Iterate over all elements in one or more lists
SYNOPSIS
foreach varname list body
foreach varlist1 list1 ?varlist2 list2 ...? body
_________________________________________________________________DESCRIPTION
The foreach command implements a loop where the loop variable(s) take on values from one or more lists. In the simplest case there is one
loop variable, varname, and one list, list, that is a list of values to assign to varname. The body argument is a Tcl script. For each
element of list (in order from first to last), foreach assigns the contents of the element to varname as if the lindex command had been
used to extract the element, then calls the Tcl interpreter to execute body.
In the general case there can be more than one value list (e.g., list1 and list2), and each value list can be associated with a list of
loop variables (e.g., varlist1 and varlist2). During each iteration of the loop the variables of each varlist are assigned consecutive
values from the corresponding list. Values in each list are used in order from first to last, and each value is used exactly once. The
total number of loop iterations is large enough to use up all the values from all the value lists. If a value list does not contain enough
elements for each of its loop variables in each iteration, empty values are used for the missing elements.
The break and continue statements may be invoked inside body, with the same effect as in the for command. Foreach returns an empty string.
EXAMPLES
This loop prints every value in a list together with the square and cube of the value:
set values {1 3 5 7 2 4 6 8} ;# Odd numbers first, for fun!
puts "Value Square Cube" ;# Neat-looking header
foreach x $values { ;# Now loop and print...
puts " $x [expr {$x**2}] [expr {$x**3}]"
}
The following loop uses i and j as loop variables to iterate over pairs of elements of a single list.
set x {}
foreach {i j} {a b c d e f} {
lappend x $j $i
}
# The value of x is "b a d c f e"
# There are 3 iterations of the loop.
The next loop uses i and j to iterate over two lists in parallel.
set x {}
foreach i {a b c} j {d e f g} {
lappend x $i $j
}
# The value of x is "a d b e c f {} g"
# There are 4 iterations of the loop.
The two forms are combined in the following example.
set x {}
foreach i {a b c} {j k} {d e f g} {
lappend x $i $j $k
}
# The value of x is "a d e b f g c {} {}"
# There are 3 iterations of the loop.
SEE ALSO
for(n), while(n), break(n), continue(n)
KEYWORDS
foreach, iteration, list, looping
Tcl foreach(n)