Sponsored Content
Full Discussion: KSH nested loops?
Top Forums Shell Programming and Scripting KSH nested loops? Post 302542041 by mrice on Tuesday 26th of July 2011 12:45:06 PM
Old 07-26-2011
Holy crap that's a boneheaded mistake, thanks. How ever now I'm getting 'fi' unexpected.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grepping within nested for loops

Good morning - I have publication lists from 34 different faculty members. I need to end up with the numbers of publications in common across all 34 faculty. I need to grep person1 (last name) in list2, person1 in list3, person1 in list 4, etc., then person2 in list3, person 2 in list4, etc.,... (2 Replies)
Discussion started by: Peggy White
2 Replies

2. Shell Programming and Scripting

file reading in nested loops

I have to to read files simultaneously in two nested loops,but am getting error can anyone do the needful. useridFile=userIds.txt fname=kiran.txt exec<$useridFile while read line do echo "User IDs are..$line" USER_ID=$line REMOTE_DIR_LOCATION="/home/test/$USER_ID" SOURCE_DIR=$USER_ID... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

3. Shell Programming and Scripting

nested for loops

I need help getting over this bump on how nested for loops work in shell. Say i was comparing files in a directory in any other language my for loop would look like so for(int i=0;to then end; i++) for(int y = i+1; to the end; y++) I can't seem to understand how i can translate that... (5 Replies)
Discussion started by: taiL
5 Replies

4. Shell Programming and Scripting

Nested while loops (ksh scripting)

You can use one while inside another? I made the following script (without really knowing if I can use two while) to get 3 numbers different from each other at random: num1=$(( $RANDOM % 10 )) num2=$num1 while do num2=$(( $RANDOM % 10 )) done num3=$num1 while do while do... (1 Reply)
Discussion started by: ale.dle
1 Replies

5. UNIX for Dummies Questions & Answers

Faster than nested while read loops?

Hi experts, I just want to know if there is a better solution to my nested while read loops below: while read line; do while read line2; do while read line3; do echo "$line $line2 $line3" done < file3.txt done < file2.txt done < file1.txt >... (4 Replies)
Discussion started by: chstr_14
4 Replies

6. Shell Programming and Scripting

Nested for loops

Greetings All, The following script attempts to enumerate all users in all groups in the group file(GROUP) and echo the following information: GROUP ---> USER The script is as follows: IFS="," for GROUP in `ypcat -k group | cut -d" " -f1` do for USER in `ypcat -k group... (13 Replies)
Discussion started by: jacksolm
13 Replies

7. UNIX for Dummies Questions & Answers

Executing nested loops+foreach

It's been a while since I used csh formatting and I am having a little bit of trouble with a few things. Things seem so much easier to execute in Matlab, however I need to do this on the terminal because of the programs I am trying to interact with. So here's what I want to do: I have a file... (0 Replies)
Discussion started by: katia
0 Replies

8. Shell Programming and Scripting

two while nested loops

for server in $(echo `cat /tmp/ScanHosts_${USERSNAME}.TXT`) do for portnumber in $(echo `cat /tmp/ScanPorts_${USERSNAME}.TXT`) do #echo ${server} ${portnumber} ... (3 Replies)
Discussion started by: SkySmart
3 Replies

9. Shell Programming and Scripting

ksh - Need Help Reducing Nested Loops

Hello, I pulled out some old code from an unfinished project the other day and wanted to stream line it better. I know anything beyond a double loop is usually bad practice, and I came up with some logic for later that would no longer require the first loop in the following code that works: ... (5 Replies)
Discussion started by: Azrael
5 Replies
libtalloc_dts(3)						      talloc							  libtalloc_dts(3)

NAME
libtalloc_dts - Chapter 3: Dynamic type system Dynamic type system Generic programming in the C language is very difficult. There is no inheritance nor templates known from object oriented languages. There is no dynamic type system. Therefore, generic programming in this language is usually done by type-casting a variable to void* and transferring it through a generic function to a specialized callback as illustrated on the next listing. void generic_function(callback_fn cb, void *pvt) { /* do some stuff and call the callback */ cb(pvt); } void specific_callback(void *pvt) { struct specific_struct *data; data = (struct specific_struct*)pvt; /* ... */ } void specific_function() { struct specific_struct data; generic_function(callback, &data); } Unfortunately, the type information is lost as a result of this type cast. The compiler cannot check the type during the compilation nor are we able to do it at runtime. Providing an invalid data type to the callback will result in unexpected behaviour (not necessarily a crash) of the application. This mistake is usually hard to detect because it is not the first thing which comes the mind. As we already know, every talloc context contains a name. This name is available at any time and it can be used to determine the type of a context even if we lose the type of a variable. Although the name of the context can be set to any arbitrary string, the best way of using it to simulate the dynamic type system is to set it directly to the type of the variable. It is recommended to use one of talloc() and talloc_array() (or its variants) to create the context as they set its name to the name of the given type automatically. If we have a context with such as a name, we can use two similar functions that do both the type check and the type cast for us: o talloc_get_type() o talloc_get_type_abort() Examples The following example will show how generic programming with talloc is handled - if we provide invalid data to the callback, the program will be aborted. This is a sufficient reaction for such an error in most applications. void foo_callback(void *pvt) { struct foo *data = talloc_get_type_abort(pvt, struct foo); /* ... */ } int do_foo() { struct foo *data = talloc_zero(NULL, struct foo); /* ... */ return generic_function(foo_callback, data); } But what if we are creating a service application that should be running for the uptime of a server, we may want to abort the application during the development process (to make sure the error is not overlooked) and try to recover from the error in the customer release. This can be achieved by creating a custom abort function with a conditional build. void my_abort(const char *reason) { fprintf(stderr, "talloc abort: %s0, reason); #ifdef ABORT_ON_TYPE_MISMATCH abort(); #endif } The usage of talloc_get_type_abort() would be then: talloc_set_abort_fn(my_abort); TALLOC_CTX *ctx = talloc_new(NULL); char *str = talloc_get_type_abort(ctx, char); if (str == NULL) { /* recovery code */ } /* talloc abort: ../src/main.c:25: Type mismatch: name[talloc_new: ../src/main.c:24] expected[char] */ Version 2.0 Tue Jun 17 2014 libtalloc_dts(3)
All times are GMT -4. The time now is 04:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy