- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: export variables to outside of a script
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
тАО06-21-2006 12:49 PM
тАО06-21-2006 12:49 PM
Re: export variables to outside of a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2006 12:57 PM
тАО06-21-2006 12:57 PM
Re: export variables to outside of a script
Assuming your script doesn't have any other output, you would use:
echo "export FOO=$FOO;"
echo "export BAR=$BAR;"
Then the callers of your script would use:
eval $(sub_script_that_wants_to_export)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2006 01:01 PM
тАО06-21-2006 01:01 PM
Re: export variables to outside of a script
Look at the manpages for 'resize'. Dennis is pointing out that another way we can communicate between processes is to have a process return information by echoing (printing) a string:
# cat /tmp/C
#!/usr/bin/sh
echo $(resize)
# cat /tmp/D
#!/usr/bin/sh
VAR=$(/tmp/C)
echo "I was told ${VAR}"
# /tmp/D
I was told COLUMNS=80; LINES=24; export COLUMNS LINES;
...Now, using our FRUIT variable:
# cat /tmp/E
#!/usr/bin/sh
echo "export FRUIT=oranges"
# cat /tmp/F
#!/usr/bin/sh
eval $(/tmp/E)
echo "I was offered some ${FRUIT}"
# /tmp/F
I was offered some oranges
The 'eval' essentially makes a two-pass sweep to allow parameter substitution for keywords and characters that would otherwise be unrecognized in the resulting commands.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2006 01:06 PM
тАО06-21-2006 01:06 PM
Re: export variables to outside of a script
I got it now!!
thank you very much!
you guys are really good!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2006 01:19 PM
тАО06-21-2006 01:19 PM
Re: export variables to outside of a script
The term 'sourcing' is somewhat unique to Unix and describes the smallest shell command, namely the . (dot). What the dot accomplishes is to prevent a subshell from running, but instead, interprets the script in the current shell. So you 'source' your script and all the changes inside the script stay in the current shell. If your script exports any variables, they are available to other scripts (and programs). The env command shows all the variables which will pass to child processes (aka, the environment).
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2006 11:33 PM
тАО06-21-2006 11:33 PM
Re: export variables to outside of a script
for this purpose I once made a script 'add2env'. In scripts, which need such a feature I call it in a way like that:
...
eval `add2env -B -d: LD_LIBRARY_PATH /path1 /path2`
add2env is written in tcsh (the project requesting the programmed features wanted it that way ...) using builtin commands only - no external progs are used.
add2env takes care not to enter values in array-like variables twice.
Containing some german words, the usage is understandable nevertheless, I think.
usage: add2env [-d delimchar] ADD2THISVAR val1 ...
Optionen:
-B Bourne/KornShell Stil
-C Tcsh/CSH Stil (default)
-D Delete der Werte statt add
-l lokale Variablen (statt Environment)
-d c delimiter ist 'c' (default: ' ')
nur bei ADD:
-0 neue Werte vorne hinsetzen
-1 neue Werte an vorletzte Stelle hinsetzen
nur bei DELETE:
-u unset der Variable, wenn leer
mfG Peter
- « Previous
-
- 1
- 2
- Next »