<?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 shell substitution in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530820#M701510</link>
    <description>Hi!&lt;BR /&gt;&lt;BR /&gt;Working on the following problem&lt;BR /&gt;&lt;BR /&gt;I have script for example:&lt;BR /&gt;export rx1=hostname1&lt;BR /&gt;export rx2=hostname2&lt;BR /&gt;export rx3=hostname3&lt;BR /&gt;for i in 1 2 3&lt;BR /&gt;do&lt;BR /&gt;ssh $(rx$i) &amp;lt;- need to get here hostname1, hostname2 etc &lt;BR /&gt;.....&lt;BR /&gt;.....&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;How to do that?&lt;BR /&gt;i only get rx1 or rx2 or rx3 instead of hostname1, hostname2 or hostname3&lt;BR /&gt;&lt;BR /&gt;thank you</description>
    <pubDate>Sun, 24 Apr 2005 23:57:40 GMT</pubDate>
    <dc:creator>Igor Sovin</dc:creator>
    <dc:date>2005-04-24T23:57:40Z</dc:date>
    <item>
      <title>shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530820#M701510</link>
      <description>Hi!&lt;BR /&gt;&lt;BR /&gt;Working on the following problem&lt;BR /&gt;&lt;BR /&gt;I have script for example:&lt;BR /&gt;export rx1=hostname1&lt;BR /&gt;export rx2=hostname2&lt;BR /&gt;export rx3=hostname3&lt;BR /&gt;for i in 1 2 3&lt;BR /&gt;do&lt;BR /&gt;ssh $(rx$i) &amp;lt;- need to get here hostname1, hostname2 etc &lt;BR /&gt;.....&lt;BR /&gt;.....&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;How to do that?&lt;BR /&gt;i only get rx1 or rx2 or rx3 instead of hostname1, hostname2 or hostname3&lt;BR /&gt;&lt;BR /&gt;thank you</description>
      <pubDate>Sun, 24 Apr 2005 23:57:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530820#M701510</guid>
      <dc:creator>Igor Sovin</dc:creator>
      <dc:date>2005-04-24T23:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530821#M701511</link>
      <description>for i in hostname1 hostname2 hostname3&lt;BR /&gt;do&lt;BR /&gt;ssh $i&lt;BR /&gt;&lt;BR /&gt;..&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;OR&lt;BR /&gt;&lt;BR /&gt;make entries in file /tmp/a&lt;BR /&gt;&lt;BR /&gt;hostname1&lt;BR /&gt;hostname2&lt;BR /&gt;hostname3&lt;BR /&gt;&lt;BR /&gt;Then in the script&lt;BR /&gt;&lt;BR /&gt;for i in `cat /tmp/a`&lt;BR /&gt;do&lt;BR /&gt;ssh $i&lt;BR /&gt;..&lt;BR /&gt;..&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 25 Apr 2005 00:11:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530821#M701511</guid>
      <dc:creator>T G Manikandan</dc:creator>
      <dc:date>2005-04-25T00:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530822#M701512</link>
      <description>Shame on me! its so easy :)&lt;BR /&gt;&lt;BR /&gt;thank you!</description>
      <pubDate>Mon, 25 Apr 2005 00:13:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530822#M701512</guid>
      <dc:creator>Igor Sovin</dc:creator>
      <dc:date>2005-04-25T00:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530823#M701513</link>
      <description>Hi Igor,&lt;BR /&gt;&lt;BR /&gt;Use array.&lt;BR /&gt;&lt;BR /&gt;insert this line&lt;BR /&gt;&lt;BR /&gt;rx=3&lt;BR /&gt;export rx[1]=hostname1&lt;BR /&gt;export rx[2]=hostname2&lt;BR /&gt;export rx[3]=hostname3&lt;BR /&gt;&lt;BR /&gt;for i in 1 2 3&lt;BR /&gt;do&lt;BR /&gt;ssh ${rx[$i]}&lt;BR /&gt;&lt;BR /&gt;.....&lt;BR /&gt;.....&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Hope it helps.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Paul</description>
      <pubDate>Mon, 25 Apr 2005 00:19:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530823#M701513</guid>
      <dc:creator>Paul_481</dc:creator>
      <dc:date>2005-04-25T00:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530824#M701514</link>
      <description>thank you guys!&lt;BR /&gt;Both methods are work!</description>
      <pubDate>Mon, 25 Apr 2005 00:22:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530824#M701514</guid>
      <dc:creator>Igor Sovin</dc:creator>
      <dc:date>2005-04-25T00:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530825#M701515</link>
      <description>You got the answer. You can use array's effectivly as,&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;export rx[1]=hostname1&lt;BR /&gt;export rx[2]=hostname2&lt;BR /&gt;export rx[3]=hostname3&lt;BR /&gt;let i=0&lt;BR /&gt;&lt;BR /&gt;while [[ $i -lt ${#rx[*]} ]]&lt;BR /&gt;do&lt;BR /&gt;  ssh ${rx[$i]}&lt;BR /&gt;  let i=i+1&lt;BR /&gt;done  &lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;##&lt;BR /&gt;&lt;BR /&gt;HTH.</description>
      <pubDate>Mon, 25 Apr 2005 04:51:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530825#M701515</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-04-25T04:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530826#M701516</link>
      <description>The construct $() has the results of a command execution. When you place just the variable inside the parens (), the shell tries to run the string rx1$hostname1 which is not what you want. Just remove the command substitution and it works fine:&lt;BR /&gt; &lt;BR /&gt;export rx1=hostname1&lt;BR /&gt;export rx2=hostname2&lt;BR /&gt;export rx3=hostname3&lt;BR /&gt;for i in 1 2 3&lt;BR /&gt;do&lt;BR /&gt;ssh rx$i ...&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;Although the ${} curly braces are not needed in this context, it is always good script writing practice to explicitly separate variables from plaintext as in:&lt;BR /&gt; &lt;BR /&gt;ssh rx${i} ...&lt;BR /&gt;</description>
      <pubDate>Mon, 25 Apr 2005 07:08:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530826#M701516</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-04-25T07:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530827#M701517</link>
      <description>Hi logor&lt;BR /&gt;1. Make one file contains all hosts &lt;BR /&gt;#vi allhosts&lt;BR /&gt;hostname1&lt;BR /&gt;hostname2&lt;BR /&gt;hostname3&lt;BR /&gt;#vi yourscript&lt;BR /&gt;for i in `cat hosts`&lt;BR /&gt;do&lt;BR /&gt;ssh $i&lt;BR /&gt;done&lt;BR /&gt;Try it now&lt;BR /&gt;HTH&lt;BR /&gt;tienna</description>
      <pubDate>Tue, 26 Apr 2005 01:58:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530827#M701517</guid>
      <dc:creator>Nguyen Anh Tien</dc:creator>
      <dc:date>2005-04-26T01:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530828#M701518</link>
      <description>A much simpler way to use the array method (which I like) is:&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;rx[1]=hostname1&lt;BR /&gt;rx[2]=hostname2&lt;BR /&gt;rx[3]=hostname3&lt;BR /&gt;export rx&lt;BR /&gt;&lt;BR /&gt;for i in ${rx[@]}&lt;BR /&gt;do&lt;BR /&gt;echo ssh ${i}&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;This [@] is much more general and expands to the entire array list.&lt;BR /&gt;You don't have to do any counting or know how big the array is!!&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt;bv</description>
      <pubDate>Tue, 26 Apr 2005 08:22:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530828#M701518</guid>
      <dc:creator>Bob_Vance</dc:creator>
      <dc:date>2005-04-26T08:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: shell substitution</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530829#M701519</link>
      <description>So basically you're wanting to do multi-level evaluation.&lt;BR /&gt;&lt;BR /&gt;You first want to evaluate $i to be a digit, which is working.. You then want to re-evaluate the new string to get the contents of the next variable.. i.e.&lt;BR /&gt;&lt;BR /&gt;rx$i =&amp;gt; rx1&lt;BR /&gt;&lt;BR /&gt;You then want to get:&lt;BR /&gt;&lt;BR /&gt;$rx1 =&amp;gt; &lt;HOSTNAME&gt;&lt;BR /&gt;&lt;BR /&gt;but that second part wasn't working.&lt;BR /&gt;&lt;BR /&gt;You can use one of the other solutions here, of which I'd highly reccomend..  But for the sake of the argument, there's usually a few ways to do the multi-level evaluation.&lt;BR /&gt;&lt;BR /&gt;One is to use the 'eval' command:&lt;BR /&gt;&lt;BR /&gt;ssh $(eval "echo \$rx$i")&lt;BR /&gt;&lt;BR /&gt;The 'eval' command allows for the second leevl of evaluation.  So the shell would work like this:&lt;BR /&gt;&lt;BR /&gt;eval "echo \$rx$i" =&amp;gt; echo $rx1 =&amp;gt; hostname1&lt;BR /&gt;&lt;BR /&gt;thus the answer you wanted.&lt;BR /&gt;&lt;BR /&gt;Anyway, have fun :)&lt;BR /&gt;&lt;/HOSTNAME&gt;</description>
      <pubDate>Tue, 26 Apr 2005 23:04:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-substitution/m-p/3530829#M701519</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2005-04-26T23:04:17Z</dc:date>
    </item>
  </channel>
</rss>

