<?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 global variables in ksh in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723310#M945477</link>
    <description>How do I get a value of a variable of a&lt;BR /&gt;child shell in the parent shell. Kind of global variables in all other program lanugages. &lt;BR /&gt;Anyhelp would be appreciated.&lt;BR /&gt;&lt;BR /&gt;Suppose if I have script like this&lt;BR /&gt;&lt;BR /&gt;-- Listing of a one.ksh&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;status=0&lt;BR /&gt;(&lt;BR /&gt;   echo "Inside the sub shell"&lt;BR /&gt;   echo "Call a Sample program "&lt;BR /&gt;   ./sample.ksh&lt;BR /&gt;   status=$?&lt;BR /&gt;   echo value of the status inside the&lt;BR /&gt;sub shell $status&lt;BR /&gt;)&lt;BR /&gt;echo value of the status outdside&lt;BR /&gt;subshell $status&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-- Listing of sample.ksh&lt;BR /&gt;ls xyz &amp;gt; /tmp/one.txt&lt;BR /&gt;&lt;BR /&gt;$./one.ksh&lt;BR /&gt;Inside the sub shell&lt;BR /&gt;Call a Sample program&lt;BR /&gt;xyz not found&lt;BR /&gt;value of the status inside the sub&lt;BR /&gt;shell 2&lt;BR /&gt;value of the status outdside subshell 0&lt;BR /&gt;&lt;BR /&gt;thanks.&lt;BR /&gt;-- David&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 14 May 2002 12:05:46 GMT</pubDate>
    <dc:creator>David Selvaraj</dc:creator>
    <dc:date>2002-05-14T12:05:46Z</dc:date>
    <item>
      <title>global variables in ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723310#M945477</link>
      <description>How do I get a value of a variable of a&lt;BR /&gt;child shell in the parent shell. Kind of global variables in all other program lanugages. &lt;BR /&gt;Anyhelp would be appreciated.&lt;BR /&gt;&lt;BR /&gt;Suppose if I have script like this&lt;BR /&gt;&lt;BR /&gt;-- Listing of a one.ksh&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;status=0&lt;BR /&gt;(&lt;BR /&gt;   echo "Inside the sub shell"&lt;BR /&gt;   echo "Call a Sample program "&lt;BR /&gt;   ./sample.ksh&lt;BR /&gt;   status=$?&lt;BR /&gt;   echo value of the status inside the&lt;BR /&gt;sub shell $status&lt;BR /&gt;)&lt;BR /&gt;echo value of the status outdside&lt;BR /&gt;subshell $status&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-- Listing of sample.ksh&lt;BR /&gt;ls xyz &amp;gt; /tmp/one.txt&lt;BR /&gt;&lt;BR /&gt;$./one.ksh&lt;BR /&gt;Inside the sub shell&lt;BR /&gt;Call a Sample program&lt;BR /&gt;xyz not found&lt;BR /&gt;value of the status inside the sub&lt;BR /&gt;shell 2&lt;BR /&gt;value of the status outdside subshell 0&lt;BR /&gt;&lt;BR /&gt;thanks.&lt;BR /&gt;-- David&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 May 2002 12:05:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723310#M945477</guid>
      <dc:creator>David Selvaraj</dc:creator>
      <dc:date>2002-05-14T12:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: global variables in ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723311#M945478</link>
      <description>Remember that a sub-shell is running as a seperate *process* and therefore in a seperate address space - so a global variable isn't global across these sub-shells - your only option is some form of inter-process communication, using files, signals, pipes etc.&lt;BR /&gt;&lt;BR /&gt;You could try something like this...&lt;BR /&gt;&lt;BR /&gt;( &lt;BR /&gt;my_script.sh&lt;BR /&gt;echo $? &lt;BR /&gt;) | read retval&lt;BR /&gt;echo "Return code was $retval"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But of course you'd have to make sure that nothing in the sub-shell sent anything to stdout or stderr.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Duncan</description>
      <pubDate>Tue, 14 May 2002 12:20:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723311#M945478</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2002-05-14T12:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: global variables in ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723312#M945479</link>
      <description>You can't return a CHILD process variable back to a parent, but you can pass a PARENT process variable to a child process using "export VARNAME".&lt;BR /&gt;&lt;BR /&gt;You can SOURCE the child process in the parent process:&lt;BR /&gt;&lt;BR /&gt;. ./sample.ksh&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Tue, 14 May 2002 12:21:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723312#M945479</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-05-14T12:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: global variables in ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723313#M945480</link>
      <description>Hi!&lt;BR /&gt;You can try this:&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;status=0&lt;BR /&gt;(&lt;BR /&gt;echo "Inside the sub shell"&lt;BR /&gt;echo "Call a Sample program "&lt;BR /&gt;./sample.ksh&lt;BR /&gt;status=$?&lt;BR /&gt;echo value of the status inside the sub shell $status&lt;BR /&gt;exit $status&lt;BR /&gt;)&lt;BR /&gt;status=$?&lt;BR /&gt;echo value of the status outdside subshell $status&lt;BR /&gt;&lt;BR /&gt;Above, I just capture the "status" value that I've set inside the sub-shell with the 'exit' command.&lt;BR /&gt;&lt;BR /&gt;Good Luck!&lt;BR /&gt;&lt;BR /&gt;Rumagoso</description>
      <pubDate>Tue, 14 May 2002 13:00:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723313#M945480</guid>
      <dc:creator>Rui Soares</dc:creator>
      <dc:date>2002-05-14T13:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: global variables in ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723314#M945481</link>
      <description>The simple answer is that you can't; by design the data flow is one way. Perhaps the easist method is to use a temp file (or a named pipe). Something like this:&lt;BR /&gt;&lt;BR /&gt;# Create PID dependant temp file names&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;PID=${$}&lt;BR /&gt;TFILE1=${TDIR}/X${PID}_1.tmp&lt;BR /&gt;&lt;BR /&gt;export TFILE1&lt;BR /&gt;&lt;BR /&gt;child.sh&lt;BR /&gt;STAT=$?&lt;BR /&gt;# child.sh would then write whatever it wants to the exported pathname ${TFILE1}&lt;BR /&gt;&lt;BR /&gt;# now read the temp file for three variables&lt;BR /&gt;&lt;BR /&gt;if [ ${STAT} -eq 0 -a -f ${TFILE1} ]&lt;BR /&gt;  then&lt;BR /&gt;    read A B C &amp;lt; ${TFILE1}&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;rm -f ${TFILE1}&lt;BR /&gt;&lt;BR /&gt;Multiple child processes could write to separate temp files.&lt;BR /&gt;&lt;BR /&gt;Using the exit status of a child process is very limited; you can only return a limited rangle of NUMERIC values and you can only return at most 1 value. The temp file method is much more flexible.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 May 2002 13:19:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723314#M945481</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-14T13:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: global variables in ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723315#M945482</link>
      <description>One way to CHEAT is using the SOURCE option:&lt;BR /&gt;&lt;BR /&gt;parent1.ksh&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;./child1.ksh&lt;BR /&gt;. ./child1.vars&lt;BR /&gt;echo "value of my_gotit is " $MY_GOTIT&lt;BR /&gt;echo "value of my_path is " $MY_PATH&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;child1.ksh&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;export MY_GOTIT=99962&lt;BR /&gt;export MY_PATH=/path/to/nowhere&lt;BR /&gt;env | grep "^MY_" &amp;gt;child1.vars&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Note, that in the PARENT1.KSH script, the use of ". ./child1.vars" this SOURCE's in the variables created by the CHILD process. Also note that I used MY_ as a prefix for my variable names so that in the CHILD process I can grep them easily out of the command returned by env.&lt;BR /&gt;&lt;BR /&gt;You might also want to use the CHILD's PID as a suffix for the child.vars filename making it unique for the instance it is running.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Tue, 14 May 2002 13:41:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723315#M945482</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-05-14T13:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: global variables in ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723316#M945483</link>
      <description>Thanks for all your reply. &lt;BR /&gt;I'll go ahead and use temp file logic. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-- David &lt;BR /&gt;</description>
      <pubDate>Tue, 14 May 2002 15:17:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/global-variables-in-ksh/m-p/2723316#M945483</guid>
      <dc:creator>David Selvaraj</dc:creator>
      <dc:date>2002-05-14T15:17:26Z</dc:date>
    </item>
  </channel>
</rss>

