- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- defining a global variable
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 07:30 PM
тАО03-20-2005 07:30 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 07:40 PM
тАО03-20-2005 07:40 PM
Re: defining a global variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 07:44 PM
тАО03-20-2005 07:44 PM
Re: defining a global variable
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.
eg:
count=0; is defining the variable counter as number and initialising to zero.
counterflag="y" is defining the variable counterflag as character and initialising to "y"
IA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 07:49 PM
тАО03-20-2005 07:49 PM
Re: defining a global variable
can you please expand on what you want to know.
Do you want to know how variables are used with a script (i.e. passing data between procedures with the same script)
or
how to change variables in your environment with a script (i.e. ORACLE_HOME etc).
Variables defined in script are local to that script, unless exported.
I believe all variables in a script are global to that script:
#!/usr/bin/sh
testing()
{
a=2
echo "Testing [$a]"
}
a=0
echo "main [$a]"
testing
echo "main [$a]"
will result in:
main [0]
Testing [2]
main [2]
Regards
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 08:19 PM
тАО03-20-2005 08:19 PM
Re: defining a global variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 08:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 08:52 PM
тАО03-20-2005 08:52 PM
Re: defining a global variable
see my earlier example.
The variable (a) is visible throughout the script.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2005 10:24 PM
тАО03-20-2005 10:24 PM
Re: defining a global variable
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.
For example:
var="0" #defines local variable named var with value 0.
export var #makes variable global.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2005 06:49 PM
тАО03-21-2005 06:49 PM
Re: defining a global variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2005 09:42 PM
тАО03-21-2005 09:42 PM
Re: defining a global variable
Normal script variables are treated as local for that script.
test="hai" # Local variable
IF you want to include multiple file variables then try as,
-- head.ksh --
# varaiable file
Name="test"
age="23"
#!/bin/ksh
. ./head.ksh
echo $name
echo $age
It will get information from head.ksh as header (include) file and print the data.
HTH.