<?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 a Var= to a variable that is incremented in for loop. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568018#M702622</link>
    <description>You can use while-do-done loop instead for-do-done.&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;i=1&lt;BR /&gt;&lt;BR /&gt;while read me;&lt;BR /&gt;do&lt;BR /&gt; &lt;BR /&gt;  let VAR[$i]=`who -u | grep $me`&lt;BR /&gt;  let ME[$i]=${VAR[$i]}&lt;BR /&gt;  let i=i+1&lt;BR /&gt;  &lt;BR /&gt;done &amp;lt; myfile&lt;BR /&gt;&lt;BR /&gt;It will do it.</description>
    <pubDate>Wed, 22 Jun 2005 00:41:39 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2005-06-22T00:41:39Z</dc:date>
    <item>
      <title>Setting a Var= to a variable that is incremented in for loop.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568014#M702618</link>
      <description>Example:&lt;BR /&gt;i=1&lt;BR /&gt;for me in myfile&lt;BR /&gt; do&lt;BR /&gt; MYVAR$i=`who -u | grep $me'&lt;BR /&gt; ME$i=$MYVAR$i &amp;lt;&lt;NO worky..what="" syntax="" does=""&gt;&lt;/NO&gt; i = i + 1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;probably over thinking this one...any ideas?&lt;BR /&gt;   &lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jun 2005 16:14:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568014#M702618</guid>
      <dc:creator>Bob Fohl</dc:creator>
      <dc:date>2005-06-21T16:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Var= to a variable that is incremented in for loop.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568015#M702619</link>
      <description>you'd rather be looking into array type variables if you are using ksh or posix&lt;BR /&gt;&lt;BR /&gt;example command&lt;BR /&gt;&lt;BR /&gt;# for i in 1 2 3&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; let a[$i]=$i+$i&lt;BR /&gt;&amp;gt; echo ${a[$i]}&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;2&lt;BR /&gt;4&lt;BR /&gt;6&lt;BR /&gt;&lt;BR /&gt;so, yours should look like&lt;BR /&gt;i=1&lt;BR /&gt;for me in myfile&lt;BR /&gt;do&lt;BR /&gt;MYVAR[$i]=`who -u | grep $me'&lt;BR /&gt;ME[$i]=$MYVAR[$i] &lt;BR /&gt;let i=$i+1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;now you have series of variables as follows&lt;BR /&gt;ME[1]="some string"&lt;BR /&gt;ME[2]="some other string"&lt;BR /&gt;...&lt;BR /&gt;ME[n]="yet another string"&lt;BR /&gt;&lt;BR /&gt;to do whatever your heart desires&lt;BR /&gt;&lt;BR /&gt;to reference them, use the following notation:&lt;BR /&gt;&lt;BR /&gt;string=${ME[$i]}&lt;BR /&gt;&lt;BR /&gt;where i is your array index&lt;BR /&gt;&lt;BR /&gt;hope this helps</description>
      <pubDate>Tue, 21 Jun 2005 16:28:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568015#M702619</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-06-21T16:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Var= to a variable that is incremented in for loop.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568016#M702620</link>
      <description>Use "eval"&lt;BR /&gt; &lt;BR /&gt;t=`who -u | grep $me`&lt;BR /&gt;eval "MYVAR$i=$t"&lt;BR /&gt;eval "ME$i=$MYVAR$i"&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 21 Jun 2005 16:32:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568016#M702620</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-06-21T16:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Var= to a variable that is incremented in for loop.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568017#M702621</link>
      <description>Bob, if the prior replies did not help, then be sure to explain in more detail what you are trying to eccomplish. Maybe some sample input/output? What problem are you really trying to solve, once you have that 'who' output in those variables?&lt;BR /&gt;&lt;BR /&gt;- is myfile meant to be a file with names perhaps? In that case check out grep -f and reading its output: who | grep -f myfile | ...&lt;BR /&gt;&lt;BR /&gt;If/when `who -u | grep $me` returns multple lines, should those become individually named/numbered variables?&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jun 2005 23:39:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568017#M702621</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-06-21T23:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Var= to a variable that is incremented in for loop.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568018#M702622</link>
      <description>You can use while-do-done loop instead for-do-done.&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;i=1&lt;BR /&gt;&lt;BR /&gt;while read me;&lt;BR /&gt;do&lt;BR /&gt; &lt;BR /&gt;  let VAR[$i]=`who -u | grep $me`&lt;BR /&gt;  let ME[$i]=${VAR[$i]}&lt;BR /&gt;  let i=i+1&lt;BR /&gt;  &lt;BR /&gt;done &amp;lt; myfile&lt;BR /&gt;&lt;BR /&gt;It will do it.</description>
      <pubDate>Wed, 22 Jun 2005 00:41:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568018#M702622</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-06-22T00:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Var= to a variable that is incremented in for loop.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568019#M702623</link>
      <description>Hi Bob,&lt;BR /&gt;&lt;BR /&gt;you last line should look like&lt;BR /&gt;i=`expr $i +1`&lt;BR /&gt;&lt;BR /&gt;Anyway pls let us know what is your aim behind this. maybe a simple script would solve the problem&lt;BR /&gt;&lt;BR /&gt;Cheers !!!&lt;BR /&gt;eknath</description>
      <pubDate>Wed, 22 Jun 2005 04:37:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-a-var-to-a-variable-that-is-incremented-in-for-loop/m-p/3568019#M702623</guid>
      <dc:creator>Eknath</dc:creator>
      <dc:date>2005-06-22T04:37:26Z</dc:date>
    </item>
  </channel>
</rss>

