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"`

Check this :

get_config_values_from_mediation_cfg()
{
echo | awk '/'"$1"'/
        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 = $2
                else
                        myValue = 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]
        }
' $CONFIG_FILENAME
}
===============================================
 

echo "Configuration Parser Processing $1"

echo "**********************************************************************"
echo "PROTOCOLS:"
i=0
get_config_values_from_mediation_cfg "PROTOCOL_TYPE"|while read myProtocolTypes[${i}]
do
  (( i += 1 ))
done
echo "returned array: ${myProtocolTypes[@]}"
echo "again: ${myProtocolTypes[0]}"
echo "again: ${myProtocolTypes[1]}"
echo "again: ${myProtocolTypes[2]}"

Many thanks.

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

Must be:

get_config_values_from_mediation_cfg()
{
awk '/'"$1"'/
        BEGIN {
                FS = "="
                count = 0

Please, read the rules:

No duplicate postings: