<?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 Question about shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162966#M664609</link>
    <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt;I make a shell script and i want to do this:&lt;BR /&gt;&lt;BR /&gt;VAR1="casa"&lt;BR /&gt;VAR2=1&lt;BR /&gt;&lt;BR /&gt;echo $(echo VAR${VAR2})&lt;BR /&gt;&lt;BR /&gt;The result is "VAR1" instead of "casa".&lt;BR /&gt;&lt;BR /&gt;What was I doing wrong???&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 12 Mar 2009 12:37:51 GMT</pubDate>
    <dc:creator>Gustavo Souza Lima</dc:creator>
    <dc:date>2009-03-12T12:37:51Z</dc:date>
    <item>
      <title>Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162966#M664609</link>
      <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt;I make a shell script and i want to do this:&lt;BR /&gt;&lt;BR /&gt;VAR1="casa"&lt;BR /&gt;VAR2=1&lt;BR /&gt;&lt;BR /&gt;echo $(echo VAR${VAR2})&lt;BR /&gt;&lt;BR /&gt;The result is "VAR1" instead of "casa".&lt;BR /&gt;&lt;BR /&gt;What was I doing wrong???&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Mar 2009 12:37:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162966#M664609</guid>
      <dc:creator>Gustavo Souza Lima</dc:creator>
      <dc:date>2009-03-12T12:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162967#M664610</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;To me, it looks correct. It should echo "VAR1". If you want "casa1" to be echo'd, then the command should be&lt;BR /&gt;#echo $VAR1$VAR2&lt;BR /&gt;&lt;BR /&gt;Good luck&lt;BR /&gt;Shahul</description>
      <pubDate>Thu, 12 Mar 2009 12:46:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162967#M664610</guid>
      <dc:creator>Shahul</dc:creator>
      <dc:date>2009-03-12T12:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162968#M664611</link>
      <description>Try this and see if it is what you want:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;eval echo \${VAR${VAR2}}</description>
      <pubDate>Thu, 12 Mar 2009 12:54:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162968#M664611</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2009-03-12T12:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162969#M664612</link>
      <description>I think you would be better treating VAR1 as an array:&lt;BR /&gt;&lt;BR /&gt;VAR[1]=casa&lt;BR /&gt;VAR2=1&lt;BR /&gt;echo ${VAR[$VAR2]}</description>
      <pubDate>Thu, 12 Mar 2009 12:55:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162969#M664612</guid>
      <dc:creator>Mark McDonald_2</dc:creator>
      <dc:date>2009-03-12T12:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162970#M664613</link>
      <description>Shahul,&lt;BR /&gt;&lt;BR /&gt;   I want print the content of the variable VAR1.&lt;BR /&gt;&lt;BR /&gt;My will is, in the first echo - (echo VAR${VAR2}) print VAR1 and with the second echo command - (echo $VAR1) print "casa".</description>
      <pubDate>Thu, 12 Mar 2009 12:56:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162970#M664613</guid>
      <dc:creator>Gustavo Souza Lima</dc:creator>
      <dc:date>2009-03-12T12:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162971#M664614</link>
      <description>&lt;!--!*#--&gt;I believe Patrick is on the right track.&lt;BR /&gt;Variable expansion doesnt work that easy.&lt;BR /&gt;What you can do if you run bash or maybe ksh (not really sure actually) is the following.&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;array[1]="Casa"&lt;BR /&gt;array[2]="Next thing"&lt;BR /&gt;array[3]="And so on"&lt;BR /&gt;&lt;BR /&gt;ptr=1&lt;BR /&gt;echo ${array[$ptr]}&lt;BR /&gt;ptr=2&lt;BR /&gt;echo ${array[$ptr]}&lt;BR /&gt;ptr=3&lt;BR /&gt;echo ${array[$ptr]}&lt;BR /&gt;&lt;BR /&gt;This also works when adding things.&lt;BR /&gt;&lt;BR /&gt;x=0&lt;BR /&gt;for i in List of words; do&lt;BR /&gt;   array[$x]=$i&lt;BR /&gt;   let x=x+1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Thu, 12 Mar 2009 12:58:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162971#M664614</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2009-03-12T12:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162972#M664615</link>
      <description>You may be able to do something like:&lt;BR /&gt;&lt;BR /&gt;typeset -n someVariable="VAR$VAR2"&lt;BR /&gt;not sure where to go with this now....&lt;BR /&gt;&lt;BR /&gt;OR&lt;BR /&gt;&lt;BR /&gt;Try what Patrick suggested.&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Mar 2009 13:05:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162972#M664615</guid>
      <dc:creator>Mark McDonald_2</dc:creator>
      <dc:date>2009-03-12T13:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162973#M664616</link>
      <description>echo $(echo VAR${VAR2})&lt;BR /&gt;&lt;BR /&gt;expands step by step like this:&lt;BR /&gt;&lt;BR /&gt;echo $(echo VAR${VAR2}) # original&lt;BR /&gt;=&amp;gt; echo $(echo VAR1)  # ${VAR2} == 1&lt;BR /&gt;=&amp;gt; echo "VAR1"      # $(echo VAR1) == "VAR1"&lt;BR /&gt;=&amp;gt; VAR1             # the output&lt;BR /&gt;&lt;BR /&gt;If you want to use the value of the variable VAR2 as a part of the name of the variable you ultimately want, you would need a construct like this:&lt;BR /&gt;&lt;BR /&gt;eval echo \${VAR${VAR2}}&lt;BR /&gt;&lt;BR /&gt;=&amp;gt; eval echo ${VAR1}  # backslash is removed, ${VAR2} == 1&lt;BR /&gt;=&amp;gt; echo casa # eval expands variables again, ${VAR1} == casa&lt;BR /&gt;=&amp;gt; casa&lt;BR /&gt;&lt;BR /&gt;You will need "eval" to trigger a second pass of variable expansion, and the backslash to protect the first $ to remain unexpanded through the first expansion pass.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Thu, 12 Mar 2009 13:06:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162973#M664616</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2009-03-12T13:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162974#M664617</link>
      <description>thanks for the posts.&lt;BR /&gt;Patrick gave me a good solution.</description>
      <pubDate>Thu, 12 Mar 2009 13:18:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162974#M664617</guid>
      <dc:creator>Gustavo Souza Lima</dc:creator>
      <dc:date>2009-03-12T13:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Question about shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162975#M664618</link>
      <description>Nill points even for my suggestions, wont be helping you again.</description>
      <pubDate>Sat, 14 Mar 2009 10:16:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-about-shell-script/m-p/5162975#M664618</guid>
      <dc:creator>Mark McDonald_2</dc:creator>
      <dc:date>2009-03-14T10:16:32Z</dc:date>
    </item>
  </channel>
</rss>

