- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- problem with global variables
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-21-2005 11:55 PM
тАО03-21-2005 11:55 PM
I'm trying to automate the procedure of adding nodes to my enviorment by writing a script.
for some reason, i'm not able to use global variables, in some parts of the script.
I have no idea why, the global variable {ExitCode} and {NODE_TYPE}, won't be updated in the outside the function.
since NODE_TYPE contains the value for 'mach_type' parameter of opcnode command,
AddToDB function fails, and since ExitCode variable updated on the function is not updated globally, test for {ExitCode} (line 289), that excute from main, succeed (while its suppose to fail)
attached tar file that contains the script and parameter file (if you try to run the script, modify OVO_SERVER parameter - set on line 30
thanks ppl
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2005 12:02 AM
тАО03-22-2005 12:02 AM
Re: problem with global variables
Is the problem that the variable don't make it from the parent to the child or that they aren't returned from the child to the parent ?
If it's that they are not going from the parent to the child, then you may need to manually "source" the variable file (i.e. if it were a global networking variable then add:
. /etc/rc.config.d/netconf to the script).
Hope that helps.
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2005 12:12 AM
тАО03-22-2005 12:12 AM
Re: problem with global variables
there are no parsing between scripts, only between diffrent function on the same script.
the thing is, there are varibles that defined first out of the function (globbaly) (1) , than one function use this variable (2), then main proggram use it again (3), and then another function use this variable (4).
sometimes, i see varible that was defined in (2) and won't be recognize at (3) or in (4).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2005 03:12 AM
тАО03-23-2005 03:12 AM
Re: problem with global variables
I was able to duplicate your problem with the following script.
#
#! /bin/sh
func1()
{
Code=1
return 0
}
func2()
{
Code=2
return 0
}
func3()
{
Code=3
return 0
}
func4()
{
Code=4
func3
return 0
}
for arg in func1 func2 func3 func4
do
$arg | tee -a xxx
echo "${Code}"
done
I was able to make it work with the following changes:
(for arg in func1 func2 func3 func4
do
$arg
echo "${Code}"
done) | tee -a xxx
Hope this helps you in figuring out how to modify your script.
Rory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2005 03:42 AM
тАО03-23-2005 03:42 AM
Re: problem with global variables
i don't understand.. where did you put the braces?
(i see a closer after done )
where would you do the return code ( $? ) test?
what about other global parameter that wont be updated? or sometimes being update and sometimes not? maybe i don't use global variable correctly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2005 04:20 AM
тАО03-23-2005 04:20 AM
Solutionitai,
( for ... done )|tee -a filename
I think the tee is causing a forked process (child) and the child is not able to update the parents variables.
A another solution would be to update the exetcodes to a tmp exitcode file. then read the results from the file.
You would have to remove the file after shell completion or when trapped.
Hope that helps
rory