- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: export Variable problem
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
Forums
Discussions
Discussions
Discussions
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
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
06-26-2002 01:06 AM
06-26-2002 01:06 AM
export Variable problem
How do I export a variable from child to parent shell?.
Example:
A.sh
-----
export XYZ=10
B.sh
echo $XYZ
B.sh
------
export XYZ=30
but I can NOT run the B.sh in the same shell using this way like ". ./B.sh" in the A.sh script.
Thanks
Vasu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2002 01:13 AM
06-26-2002 01:13 AM
Re: export Variable problem
A better way to do it is declare the variable first in the parent, then when it gets modified in the child it will also be set back in the parent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2002 01:17 AM
06-26-2002 01:17 AM
Re: export Variable problem
simple answer: you cannot. The environment of a child process is lost when it exits.
You will need to "source" the script if you want to keep the environment. Why would you not use this option? :
. /dir/B.sh
Other tricks are to put the value in a temp file and read it, put the export command in a temp file and source it, ....
good luck,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2002 01:21 AM
06-26-2002 01:21 AM
Re: export Variable problem
If you need only one value to be returned to the parent shell, you can do it by the exit from the child script like that:
A.sh
-----
export XYZ=10
sh B.sh
XYZ=$?
export XYZ
echo $XYZ
B.sh
------
export XYZ=30
exit $XYZ
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2002 01:33 AM
06-26-2002 01:33 AM
Re: export Variable problem
*No way*, you can't do this, exporting works only in one direction, from parent processes to child processes, not the other direction. You have to put the value into a file which you read in parent process later to make the value existent here.
Allways stay on the bright side of life!
Peter