<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: setting an array from an existing $VAR in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-an-array-from-an-existing-var/m-p/5173415#M663295</link>
    <description>If you want to assign arrays you can do:&lt;BR /&gt;X=A1&lt;BR /&gt;set -A A2_array -- $(eval echo "\${${X}_array[@]}" )&lt;BR /&gt;echo "Size A2: ${#A2_array[*]}"&lt;BR /&gt;echo "${A2_array[@]}"&lt;BR /&gt;&lt;BR /&gt;But I can't seem to have array elements with spaces.</description>
    <pubDate>Wed, 06 May 2009 00:23:34 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2009-05-06T00:23:34Z</dc:date>
    <item>
      <title>setting an array from an existing $VAR</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-an-array-from-an-existing-var/m-p/5173414#M663294</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I'm looking for advise on a solution I have come up with but am not sure if this is the correct way to go about it:&lt;BR /&gt;&lt;BR /&gt;I may be trying to over complicate things but I am developing a wrapper script that reads from a config file which assigns an array.  &lt;BR /&gt;&lt;BR /&gt;here are the elements of my array:&lt;BR /&gt;&lt;BR /&gt;ECM_CLUST=ECM_OAT01&lt;BR /&gt;set -A ECM_PORT&lt;BR /&gt;ECM_PORT[1]=443&lt;BR /&gt;ECM_PORT[2]=7943&lt;BR /&gt;ECM_PORT[3]=7843&lt;BR /&gt;ECM_PORT[4]=7080&lt;BR /&gt;ECM_PORT[5]=7090&lt;BR /&gt;&lt;BR /&gt;The wrapper script is called with ./&amp;lt;scriptname&amp;gt; &lt;SERVICE&gt;&lt;BR /&gt;&lt;BR /&gt;in this case service is going to be ECM but could be SIG - there are several functions in the script that expect ${SERVICE}_&lt;FUNCTION&gt;.&lt;BR /&gt;&lt;BR /&gt;The issue I had was assigning the array elements from ${ECM_PORTS[*]} to another array within the script function - below is the fuction&lt;BR /&gt;&lt;BR /&gt;${SERVICE}_Cluster_Conf () {&lt;BR /&gt;&lt;BR /&gt;SERVICE=$1&lt;BR /&gt;cnt=1&lt;BR /&gt;MAXCNT=$(eval echo \${#${SERVICE}_PORT[@]})&lt;BR /&gt;set -A SERVICE_PORT&lt;BR /&gt;&lt;BR /&gt;while [[ ${MAXCNT} -ge ${cnt} ]]&lt;BR /&gt;do&lt;BR /&gt;    eval "SERVICE_PORT[${cnt}]=\${${SERVICE}_PORT[cnt]}"&lt;BR /&gt;    echo ${SERVICE_PORT[${cnt}]}&lt;BR /&gt;    (( cnt += 1))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;echo "Loading the ${SERVICE}_CLUST address/s "&lt;BR /&gt;dscontrol cluster add ${SERVICE}_CLUST address $CLUSIP primaryhost $PRIMIP&lt;BR /&gt;dscontrol port add ${SERVICE}_CLUST:`echo "${SERVICE_PORT[*]}"|tr -s " " "+"` method nat reset no&lt;BR /&gt;dscontrol cluster set ${SERVICE}_CLUST proportions 49 50 1 0&lt;BR /&gt;#&lt;BR /&gt;echo "Adding server machines"&lt;BR /&gt;&lt;BR /&gt;dscontrol server add ${SERVICE}_CLUST:${SERVICE_PORT[1]}:$SERVER1 address $WMBIP1 mapport ${SERVICE_PORT[2]} router $AGW ret&lt;BR /&gt;urnaddress $RETIP&lt;BR /&gt;dscontrol server add ${SERVICE}_CLUST:${SERVICE_PORT[1]}:$SERVER2 address $WMBIP2 mapport ${SERVICE_PORT[3]} router $AGW ret&lt;BR /&gt;urnaddress $RETIP&lt;BR /&gt;&lt;BR /&gt;if [[ ${MAXCNT} -gt 3 ]] ; then&lt;BR /&gt;&lt;BR /&gt;    cnt=4&lt;BR /&gt;    SERVICE_MAPPORT=`expr ${SERVICE_PORT[cnt]} + 100`&lt;BR /&gt;&lt;BR /&gt;        while [ ${#SERVICE_PORT[@]} -ge ${cnt} ] ; do&lt;BR /&gt;&lt;BR /&gt;            dscontrol server add ${SERVICE}_CLUST:${SERVICE_PORT[cnt]}:$SERVER1 address $WMBIP1 router $AGW returnaddress $RE&lt;BR /&gt;TIP&lt;BR /&gt;            dscontrol server add ${SERVICE}_CLUST:${SERVICE_PORT[cnt]}:$SERVER2 address $WMBIP2 mapport ${SERVICE_MAPPORT}  r&lt;BR /&gt;outer $AGW returnaddress $RETIP&lt;BR /&gt;&lt;BR /&gt;        done&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;} # ${SERVICE}_Cluster_Conf&lt;BR /&gt;&lt;BR /&gt;##########################################&lt;BR /&gt;##########################################&lt;BR /&gt;&lt;BR /&gt;the config / vars file looks like:&lt;BR /&gt;&lt;BR /&gt;exndot1_sysconf () {&lt;BR /&gt;&lt;BR /&gt;NETMASK1=255.255.255.0&lt;BR /&gt;NETMASK2=255.255.255.0&lt;BR /&gt;NFA=10.27.84.200&lt;BR /&gt;HB_ADDR=10.27.84.201&lt;BR /&gt;CGA=10.27.90.254&lt;BR /&gt;AGW=10.27.91.254&lt;BR /&gt;CLUSIP=10.27.90.10&lt;BR /&gt;RETIP=10.27.91.10&lt;BR /&gt;PRIMIP=10.27.84.200&lt;BR /&gt;WMBIP1=10.27.111.78&lt;BR /&gt;WMBIP2=10.27.111.79&lt;BR /&gt;INTER1=en1&lt;BR /&gt;INTER2=en2&lt;BR /&gt;SERVER1=wmbot1&lt;BR /&gt;SERVER2=wmbot2&lt;BR /&gt;ECM_CLUST=ECM_OAT01&lt;BR /&gt;set -A ECM_PORT&lt;BR /&gt;ECM_PORT[1]=443&lt;BR /&gt;ECM_PORT[2]=7943&lt;BR /&gt;ECM_PORT[3]=7843&lt;BR /&gt;ECM_PORT[4]=7080&lt;BR /&gt;ECM_PORT[5]=7090&lt;BR /&gt;&lt;BR /&gt;SIG_PORT[1]=444&lt;BR /&gt;SIG_PORT[2]=7944&lt;BR /&gt;SIG_PORT[3]=7844&lt;BR /&gt;&lt;BR /&gt;} # exndot1_sysconf&lt;BR /&gt;&lt;BR /&gt;#################################&lt;BR /&gt;#################################&lt;BR /&gt;&lt;BR /&gt;The solution have questioned myself which has taken a bit of hacking is:&lt;BR /&gt;&lt;BR /&gt;SERVICE=ECM&lt;BR /&gt;cnt=1&lt;BR /&gt;MAXCNT=$(eval echo \${#${SERVICE}_PORT[@]})&lt;BR /&gt;set -A SERVICE_PORT&lt;BR /&gt;&lt;BR /&gt;while [[ ${MAXCNT} -ge ${cnt} ]]&lt;BR /&gt;do&lt;BR /&gt;    eval "SERVICE_PORT[${cnt}]=\${${SERVICE}_PORT[cnt]}"&lt;BR /&gt;    echo ${SERVICE_PORT[${cnt}]}&lt;BR /&gt;    (( cnt += 1))&lt;BR /&gt;done&lt;BR /&gt;443&lt;BR /&gt;7943&lt;BR /&gt;7843&lt;BR /&gt;7080&lt;BR /&gt;7090&lt;BR /&gt;&lt;BR /&gt;appologies if I haven't explained well and I understand that this could be quite confusing but is there a less complicated approach I should be taking?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Chris&lt;BR /&gt;&lt;/FUNCTION&gt;&lt;/SERVICE&gt;</description>
      <pubDate>Tue, 05 May 2009 14:43:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-an-array-from-an-existing-var/m-p/5173414#M663294</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2009-05-05T14:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: setting an array from an existing $VAR</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-an-array-from-an-existing-var/m-p/5173415#M663295</link>
      <description>If you want to assign arrays you can do:&lt;BR /&gt;X=A1&lt;BR /&gt;set -A A2_array -- $(eval echo "\${${X}_array[@]}" )&lt;BR /&gt;echo "Size A2: ${#A2_array[*]}"&lt;BR /&gt;echo "${A2_array[@]}"&lt;BR /&gt;&lt;BR /&gt;But I can't seem to have array elements with spaces.</description>
      <pubDate>Wed, 06 May 2009 00:23:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-an-array-from-an-existing-var/m-p/5173415#M663295</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-05-06T00:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: setting an array from an existing $VAR</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-an-array-from-an-existing-var/m-p/5173416#M663296</link>
      <description>great stuff cheers Dennis.&lt;BR /&gt;&lt;BR /&gt;regards&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Wed, 06 May 2009 08:04:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-an-array-from-an-existing-var/m-p/5173416#M663296</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2009-05-06T08:04:49Z</dc:date>
    </item>
  </channel>
</rss>

