- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Environment variables in shell 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
Forums
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
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
тАО12-26-2006 12:39 PM
тАО12-26-2006 12:39 PM
Environment variables in shell script
Is it possible in HP-UX 11.
For example:
1st script ( env.sh )
DBCONNECTION=/usr/local/etc/param.pf; export DBCONNECTION
2nd script ( dbprod.sh )
sh env.sh
mpro -pf $DBCONNECTION
When I call the 2nd script the environment variables as empty and the application doens't start.
Please, help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-26-2006 01:12 PM
тАО12-26-2006 01:12 PM
Re: Environment variables in shell script
You need to 'source' or read your variables. For example:
# cat ./sh1
#!/usr/bin/sh
DBCONNECTION=/usr/local/etc/param.pf
# cat ./sh2
#!/usr/bin/sh
. ./sh1
mpro -pf ${DBCONNECTION}
That is, you use a dot (".") operator followed by a blank (space), followed by the name of the file to be 'source'd (read, or included).
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-26-2006 02:59 PM
тАО12-26-2006 02:59 PM
Re: Environment variables in shell script
standard script", you're actually running
that shell script in its own process, and
that shell process has its own environment.
Setting an environment variable in that
shell's environment does nothing to the
environment of the original shell's process.
Using the "." command causes the original
shell to read and execute the second script's
commands, so those commands now affect the
environment of the original shell process
(which is the only process in this case).
Note, too, that when using ".", the second
"script" file does not need to be executable,
and it does not need a "#!shell_path" on its
first line. (That's because it's not really
being used as a shell script, only as a kind
of data file for the first shell script.)
Of course, if that second file _is_
executable then you can also use it as a
shell script, and then you'll probably want
to include a "#!shell_path" in it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-26-2006 05:18 PM
тАО12-26-2006 05:18 PM
Re: Environment variables in shell script
As suggested by James u have to run env.sh in
the same shell, if u r using
sh env.sh
then a child shell process is created,
the exported variables in env.sh will be
available to processes which r child of shell
running env.sh, hence after
sh env.sh
these variables r distroyed, to prevent this
and make ur exported variables in same shell
use
. env.sh
using . (dot) will tell shell to run process in
current shell only, thus all the shell
variables in env.sh will be available in ur
2nd script dbprod.sh
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-01-2007 08:06 PM
тАО01-01-2007 08:06 PM
Re: Environment variables in shell script
export the varaiable in the first script. execute it as '.' script, and you will be able to see the variable in teh other script:
1:
/> cat test1
#!/usr/bin/ksh
export A="I'm A"
#eof
2:/> cat test2
#!/usr/bin/ksh
. test1
echo "I'm test2"
echo $A
#eof
3:> test2
I'm test2
I'm A
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-01-2007 08:40 PM
тАО01-01-2007 08:40 PM
Re: Environment variables in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-01-2007 09:25 PM
тАО01-01-2007 09:25 PM
Re: Environment variables in shell script
Tks.