HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- global variables
Operating System - Linux
1827990
Members
2416
Online
109973
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
05-05-2006 07:13 AM
05-05-2006 07:13 AM
I use ksh and have the following function
function fun1 () {
source=$1
target=$2
}
function fun2 () {
echo $source
echo $target
}
it will not echo $source and $target, because they were defined in a function. how can other function use it? I dont wish to define it in the main....too messy if I have more variables.
function fun1 () {
source=$1
target=$2
}
function fun2 () {
echo $source
echo $target
}
it will not echo $source and $target, because they were defined in a function. how can other function use it? I dont wish to define it in the main....too messy if I have more variables.
Solved! Go to Solution.
- Tags:
- variable
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2006 07:39 AM
05-05-2006 07:39 AM
Solution
Hi Gemini:
Actually, the way you have written this, 'source' and 'target' are global once you have called 'fun1'.
If you call 'fun2' first and then 'fun1' the 'source' and 'target' are undefined.
If both functions need to see the variable it must be either global (in main) or you must pass it to function. Within a function you can localize a variable by declaring it with a 'typeset'.
function fun1 {
typeset source=$1
typeset target=$2
Regards!
...JRF...
Actually, the way you have written this, 'source' and 'target' are global once you have called 'fun1'.
If you call 'fun2' first and then 'fun1' the 'source' and 'target' are undefined.
If both functions need to see the variable it must be either global (in main) or you must pass it to function. Within a function you can localize a variable by declaring it with a 'typeset'.
function fun1 {
typeset source=$1
typeset target=$2
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2006 08:08 AM
05-05-2006 08:08 AM
Re: global variables
yes, I think that I have my function reversed......thank you!!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP