![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| function return array | dophine | Shell Programming and Scripting | 6 | 05-06-2008 01:16 PM |
| Perl - New line in array elements | bperl | Shell Programming and Scripting | 4 | 04-03-2008 10:56 PM |
| pass each elements in array to ssytem command | jaganadh | Shell Programming and Scripting | 0 | 12-14-2007 06:57 AM |
| How can i read array elements dynamically in bash? | haisubbu | UNIX for Dummies Questions & Answers | 1 | 08-29-2006 03:19 AM |
| how to return an array of elements from oracle to shell script | satyakiran | Shell Programming and Scripting | 3 | 08-02-2005 10:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
To return the elements of array
Hi,
Please can someone help to return the array elements from a function. Currently the problem I face is that tempValue stores the value in myValue[] as a string while I need an array of values to be returned instead of string. Many Thanks, Sudhakar the function called is: get_config_values_from_mediation_cfg() { i=0 tempValue=`grep $1 $CONFIG_FILENAME | awk ' BEGIN { FS = "=" count = 0 i = 0 } NF == 2 && !/^#/ { gsub(/"/, "") # Remove stroke characters gsub(" ", "") # Remove spaces gsub("\n", "") # Remove new line character checkForCommentSymbol = index ( $2, "#" ) if ( checkForCommentSymbol == 0 ) myValue[i] = $2 else myValue[i] = substr( $2, 1, checkForCommentSymbol - 1 ) count++ i++ } END { if ( count == 0 ) print "NO_VALUE" else if ( count == 1 ) print myValue else #print "INVALID_VALUES" for (j=0; j<=i; j++) print myValue[j] } '` echo "${tempValue[@]}" } =============================================== echo "Configuration Parser Processing $1" echo "**********************************************************************" echo "PROTOCOLS:" myProtocolTypes=`get_config_values_from_mediation_cfg "PROTOCOL_TYPE"` echo "returned array: ${myProtocolTypes[@]}" echo "again: ${myProtocolTypes[0]}" echo "again: ${myProtocolTypes[1]}" echo "again: ${myProtocolTypes[2]}" #for (i=0; i<3; i++) for i in 0 1 2 do echo "once more: ${myProtocolTypes[$i]}" done awk ' {split ($1, a, " "); print a[1]} ' $myProtocolTypes #awk ' {split (myProtocolTypes, a,); print a[1]} ' echo "FILENAME_PATTERNS:" echo `get_config_values_from_mediation_cfg "FILENAME_PATTERN"` echo "MODES:" echo `get_config_values_from_mediation_cfg "MODE"` echo "CONFIG_FILENAMES:" echo `get_config_values_from_mediation_cfg "CONFIG_FILENAME"` |
|
||||
|
the first value is blank
Hi,
Please can you someone help me out to eliminate the problem. Here, it correctly prints the myFilenameCount but returns the first value of array myFilenamePatterns as blank. Thanks, Sudhakar i=0 get_config_values_from_mediation_cfg "FILENAME_PATTERN"|while read myFilenamePatterns[${i}] do echo "FilenamePattern: ${myFilenamePatterns[$i]}" (( i += 1 )) done myFilenameCount=${i} echo $myFilenameCount echo "returned array: ${myFilenamePatterns[@]}" i=0 while [ $i -lt $myFilenameCount ] do echo "FilenamePatterns: ${myFilenamePatterns[${i}]}" (( i += 1 )) done Last edited by Sudhakar333; 08-06-2007 at 08:01 AM.. |
|
|||||
|
Please, read the rules:
Quote:
http://www.unix.com/shell-programmin...rns-blank.html |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|