<?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: defining a global variable in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508372#M843922</link>
    <description>In general all shell variable are global within a shell script. However: If you are calling non shell routines within the script then the varables within those routines will be local to that routine. What I meen by a non shell routine is if you are using awk, perl, sql, or other executables that can be called in-line from shell that is not shell. Usually you will have to pass varables to this routines. I.E. awk -v INDATE=${INDATE}</description>
    <pubDate>Tue, 22 Mar 2005 10:52:30 GMT</pubDate>
    <dc:creator>Lawrence Mahan</dc:creator>
    <dc:date>2005-03-22T10:52:30Z</dc:date>
    <item>
      <title>defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508362#M843912</link>
      <description>i would like to ask hot to define a global and local variable in a script?&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Mar 2005 03:30:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508362#M843912</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2005-03-21T03:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508363#M843913</link>
      <description>What exactly do you mean by global?</description>
      <pubDate>Mon, 21 Mar 2005 03:40:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508363#M843913</guid>
      <dc:creator>Noel Miranda</dc:creator>
      <dc:date>2005-03-21T03:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508364#M843914</link>
      <description>Hi Fernando,&lt;BR /&gt;&lt;BR /&gt;A global variable is global to the script and can be accessed anywhere in the script. A local variable is local to a function or a loop which can be referred in the function or the loop.&lt;BR /&gt;eg:&lt;BR /&gt;&lt;BR /&gt;count=0; is defining the variable counter as number and initialising to zero.&lt;BR /&gt;counterflag="y" is defining the variable counterflag as character and initialising to "y"&lt;BR /&gt;&lt;BR /&gt;IA&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Mar 2005 03:44:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508364#M843914</guid>
      <dc:creator>Indira Aramandla</dc:creator>
      <dc:date>2005-03-21T03:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508365#M843915</link>
      <description>Fernando,&lt;BR /&gt;can you please expand on what you want to know.&lt;BR /&gt;Do you want to know how variables are used with a script (i.e. passing data between procedures with the same script)&lt;BR /&gt;or&lt;BR /&gt;how to change variables in your environment with a script (i.e. ORACLE_HOME etc).&lt;BR /&gt;Variables defined in script are local to that script, unless exported.&lt;BR /&gt;I believe all variables in a script are global to that script:&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;testing()&lt;BR /&gt;{&lt;BR /&gt;a=2&lt;BR /&gt;echo "Testing [$a]"&lt;BR /&gt;}&lt;BR /&gt;a=0&lt;BR /&gt;echo "main [$a]"&lt;BR /&gt;testing&lt;BR /&gt;echo "main [$a]"&lt;BR /&gt;&lt;BR /&gt;will result in:&lt;BR /&gt;main [0]&lt;BR /&gt;Testing [2]&lt;BR /&gt;main [2]&lt;BR /&gt;&lt;BR /&gt;Regards &lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Mar 2005 03:49:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508365#M843915</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-03-21T03:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508366#M843916</link>
      <description>Basically, i want to know  how variables are used within a script (i.e. passing data between procedures with the same script)? Are they accessible anywhere within the script?&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Mar 2005 04:19:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508366#M843916</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2005-03-21T04:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508367#M843917</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Just export the variable.</description>
      <pubDate>Mon, 21 Mar 2005 04:23:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508367#M843917</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-03-21T04:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508368#M843918</link>
      <description>Fernando,&lt;BR /&gt;see my earlier example.&lt;BR /&gt;The variable (a) is visible throughout the script.&lt;BR /&gt;Regards</description>
      <pubDate>Mon, 21 Mar 2005 04:52:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508368#M843918</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-03-21T04:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508369#M843919</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;Local variables are available within a single shell instance. If other instances of a shell are invoked by a script, you need to define global variables, those can be inherited by child shells.&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;var="0"   #defines local variable named var with value 0.&lt;BR /&gt;&lt;BR /&gt;export var #makes variable global.</description>
      <pubDate>Mon, 21 Mar 2005 06:24:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508369#M843919</guid>
      <dc:creator>Artyom Voronchihin</dc:creator>
      <dc:date>2005-03-21T06:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508370#M843920</link>
      <description>If you want a variable to be available to everybody at all times, export it in "/etc/profile".</description>
      <pubDate>Tue, 22 Mar 2005 02:49:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508370#M843920</guid>
      <dc:creator>Andrew Cowan</dc:creator>
      <dc:date>2005-03-22T02:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508371#M843921</link>
      <description>We can define global variables with login startup scripts, /etc/profile or home directory profile file. &lt;BR /&gt;&lt;BR /&gt;Normal script variables are treated as local for that script. &lt;BR /&gt;&lt;BR /&gt;test="hai" # Local variable&lt;BR /&gt;&lt;BR /&gt;IF you want to include multiple file variables then try as,&lt;BR /&gt;&lt;BR /&gt;-- head.ksh --&lt;BR /&gt;# varaiable file&lt;BR /&gt;Name="test"&lt;BR /&gt;age="23"&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;. ./head.ksh&lt;BR /&gt;&lt;BR /&gt;echo $name&lt;BR /&gt;echo $age&lt;BR /&gt;&lt;BR /&gt;It will get information from head.ksh as header (include) file and print the data.&lt;BR /&gt;&lt;BR /&gt;HTH.</description>
      <pubDate>Tue, 22 Mar 2005 05:42:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508371#M843921</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-03-22T05:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508372#M843922</link>
      <description>In general all shell variable are global within a shell script. However: If you are calling non shell routines within the script then the varables within those routines will be local to that routine. What I meen by a non shell routine is if you are using awk, perl, sql, or other executables that can be called in-line from shell that is not shell. Usually you will have to pass varables to this routines. I.E. awk -v INDATE=${INDATE}</description>
      <pubDate>Tue, 22 Mar 2005 10:52:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508372#M843922</guid>
      <dc:creator>Lawrence Mahan</dc:creator>
      <dc:date>2005-03-22T10:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: defining a global variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508373#M843923</link>
      <description>Actually, one can have local variables within a shell script. Those defined in functions via the typeset command are local to the function. Run this script and it should make variable scoping clear.&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i I=100 # global&lt;BR /&gt;typeset GLOVAR="Global String"&lt;BR /&gt;&lt;BR /&gt;func1()&lt;BR /&gt;{&lt;BR /&gt;  typeset -i I=1 # local definition&lt;BR /&gt;&lt;BR /&gt;  echo "I in func1 = ${I}"&lt;BR /&gt;  echo "GLOVAR in func1 = ${GLOVAR}"&lt;BR /&gt;  return 0&lt;BR /&gt;} # func1&lt;BR /&gt;&lt;BR /&gt;func2()&lt;BR /&gt;{&lt;BR /&gt;  typeset -i I=2 # local definition&lt;BR /&gt;&lt;BR /&gt;  echo "I in func2 = ${I}"&lt;BR /&gt;  echo "GLOVAR in func2 = ${GLOVAR}"&lt;BR /&gt;  return 0&lt;BR /&gt;} # func2&lt;BR /&gt;&lt;BR /&gt;func1&lt;BR /&gt;func2&lt;BR /&gt;echo "I in main = ${I}"&lt;BR /&gt;echo "GLOVAR in main = ${GLOVAR}"&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;----------------------------------------&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It's considered good practice to typeset all variables in scripts. Of course, any of these can be exported and made available to child processes.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Mar 2005 11:17:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/defining-a-global-variable/m-p/3508373#M843923</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-03-22T11:17:48Z</dc:date>
    </item>
  </channel>
</rss>

