<?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: Pass local variable to global variable in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500276#M69854</link>
    <description>Thank you so much Alex. My problem actually is to pass out the value of $cur_uid in the if loop to outside. I would say a local variable in if loop to pass its value to a global variable in the main program. In my case, I would pass the value of $cur_uid to $uidcurrent. I know some of the platform works in that way. But not in my Linux. Any thoughts</description>
    <pubDate>Tue, 08 Mar 2005 17:52:32 GMT</pubDate>
    <dc:creator>Michael Yu_2</dc:creator>
    <dc:date>2005-03-08T17:52:32Z</dc:date>
    <item>
      <title>Pass local variable to global variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500274#M69852</link>
      <description>Hello All,&lt;BR /&gt;&lt;BR /&gt;Please throw some lights to the new guy. I have a shell script as following: The idea of the program is to get the value of $cur_uid from the IF loop, assign it to uidcurrent. In my WRK_FILE, I only have one line. It either equal to UID1 or UID2. As you may see in my program, I couldn't get the ideal results. I have tried diffent shells. It just won't work. Your help will be highly appreciated.&lt;BR /&gt;&lt;BR /&gt;WRK_FILE=$newdbs_home/bin/.configdlyidcheck&lt;BR /&gt;TMP_FILE=/var/tmp/tmp.txt&lt;BR /&gt;uidcurrent=""&lt;BR /&gt;flag=""&lt;BR /&gt;cur_uid=""&lt;BR /&gt;&lt;BR /&gt;if [[ -s $WRK_FILE ]]; then&lt;BR /&gt;   cat $WRK_FILE | while read line&lt;BR /&gt;   do&lt;BR /&gt;      flag=$line&lt;BR /&gt;      echo flag: $flag&lt;BR /&gt;      if [ $flag = $UID1 ]; then&lt;BR /&gt;        cur_uid=$flag     #### this variable is used for echo/testing only&lt;BR /&gt;        nxt_uid=$UID2&lt;BR /&gt;        echo current uid in $WRK_FILE is: $cur_uid, and the next uid is: $nxt_uid &amp;gt; $TMP_FILE&lt;BR /&gt;        echo $nxt_uid &amp;gt; $WRK_FILE&lt;BR /&gt;        pg $WRK_FILE&lt;BR /&gt;      elif [ $flag = $UID2 ]; then&lt;BR /&gt;        cur_uid=$flag   ##### this line is for testing only&lt;BR /&gt;        nxt_uid=$UID1&lt;BR /&gt;        echo current uid in $WRK_FILE is: $cur_uid, and the next uid is: $nxt_uid &amp;gt; $TMP_FILE&lt;BR /&gt;        echo $nxt_uid &amp;gt; $WRK_FILE&lt;BR /&gt;        pg $WRK_FILE    ##### this line is for testing only&lt;BR /&gt;      else&lt;BR /&gt;        echo "The $WRK_FILE file is damaged and please check the load shell program" &amp;gt; $TMP_FILE&lt;BR /&gt;      fi&lt;BR /&gt;    echo "The Current User ID is: $cur_uid"&lt;BR /&gt; #  uidcurrent=$cur_uid&lt;BR /&gt;  # echo "The UIDCURRENT is: $uidcurrent"&lt;BR /&gt;  &lt;BR /&gt;  done&lt;BR /&gt; &lt;BR /&gt;  uidcurrent=$cur_uid&lt;BR /&gt;  echo "The UIDCURRENT is: $uidcurrent"&lt;BR /&gt;else&lt;BR /&gt;   echo "The $WRK_FILE file does not exist" ###&amp;gt; $TMP_FILE&lt;BR /&gt;   /bin/mail -s "The $WRK_FILE is damaged and can not load the data" ${mlist} &amp;lt; $TMP_FILE&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt; echo "the cur_uid is: $cur_uid" &amp;gt; /var/tmp/test2.txt&lt;BR /&gt; echo "The UIDCURRENT is: $uidcurrent" &amp;gt;&amp;gt; /var/tmp/test2.txt</description>
      <pubDate>Tue, 08 Mar 2005 12:23:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500274#M69852</guid>
      <dc:creator>Michael Yu_2</dc:creator>
      <dc:date>2005-03-08T12:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Pass local variable to global variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500275#M69853</link>
      <description>Yep, I ran into this annoying problem when I ported scripts from HPUX to Linux.&lt;BR /&gt;&lt;BR /&gt;Here is the solution:&lt;BR /&gt;&lt;A href="http://www.faqs.org/faqs/unix-faq/shell/bash/" target="_blank"&gt;http://www.faqs.org/faqs/unix-faq/shell/bash/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Refer to question *E4*</description>
      <pubDate>Tue, 08 Mar 2005 13:07:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500275#M69853</guid>
      <dc:creator>Alex Lavrov.</dc:creator>
      <dc:date>2005-03-08T13:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Pass local variable to global variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500276#M69854</link>
      <description>Thank you so much Alex. My problem actually is to pass out the value of $cur_uid in the if loop to outside. I would say a local variable in if loop to pass its value to a global variable in the main program. In my case, I would pass the value of $cur_uid to $uidcurrent. I know some of the platform works in that way. But not in my Linux. Any thoughts</description>
      <pubDate>Tue, 08 Mar 2005 17:52:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500276#M69854</guid>
      <dc:creator>Michael Yu_2</dc:creator>
      <dc:date>2005-03-08T17:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Pass local variable to global variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500277#M69855</link>
      <description>When things get tough in shell I move to a more complete language such as perl or python, usually python.  Setting a global variable in python is easy just prefix it with global:&lt;BR /&gt;&lt;BR /&gt;global foo = bar&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.python.org" target="_blank"&gt;www.python.org&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;--Dave</description>
      <pubDate>Tue, 08 Mar 2005 18:04:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500277#M69855</guid>
      <dc:creator>Dave Falloon</dc:creator>
      <dc:date>2005-03-08T18:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Pass local variable to global variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500278#M69856</link>
      <description>Well, the only way to do it is to get rid of the pipe and while loop. Try to replace it with something else (for loop for example) or just put it in some temp file and then read from it :) (ugly but effective)</description>
      <pubDate>Wed, 09 Mar 2005 00:07:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500278#M69856</guid>
      <dc:creator>Alex Lavrov.</dc:creator>
      <dc:date>2005-03-09T00:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Pass local variable to global variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500279#M69857</link>
      <description>Thank you guys. I have got rid of the while loop. Instead, I only use the if/then/else. It works now. But the code is really ugly.</description>
      <pubDate>Wed, 09 Mar 2005 09:00:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pass-local-variable-to-global-variable/m-p/3500279#M69857</guid>
      <dc:creator>Michael Yu_2</dc:creator>
      <dc:date>2005-03-09T09:00:36Z</dc:date>
    </item>
  </channel>
</rss>

