- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Setting Environment variable in UNIX Shell
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
тАО09-28-2007 12:47 AM
тАО09-28-2007 12:47 AM
Re: Setting Environment variable in UNIX Shell
You can't get where you want directly as stated by many. Another variation is to let your Perl script do whatever its objective is and create a file of the variables you want exported. Then, at will, source (read) them into your current environment:
# cat some.pl
#!/usr/bin/perl
open( FH, ">", 'env.sh' ) or die;
print FH "HAI=hai\n";
print FH "HELLO=Hello\n";
# ./some.pl
# . ./env.sh
echo ${HELLO}
Hello
Regards!
...JRF...
- Tags:
- source
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2007 12:57 AM
тАО09-28-2007 12:57 AM
Re: Setting Environment variable in UNIX Shell
Yes i am also thinking of the same solution but only thing is i have planned to execute both the perl script and the generated shell script through another shell script.
Ex -
!#/usr/bin/sh
Some.pl
chmod +x Env.sh
source Env.sh
Where Env.sh is the generated file.
But if i do this i m getting the error source not found. Can you correct me if i am executing the shell script in wrong way please
thanks and regards
Vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2007 01:07 AM
тАО09-28-2007 01:07 AM
Re: Setting Environment variable in UNIX Shell
> Yes i am also thinking of the same solution but only thing is i have planned to execute both the perl script and the generated shell script through another shell script.
Fine, do something like this:
#!/usr/bin/sh
echo "running Perl next"
/home/vikram/perlthing #...outputs /home/vikram/env.sh
. /home/vikram/env.sh #...sources env.sh
echo "Now I can say ${HELLO}"
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2007 01:12 AM
тАО09-28-2007 01:12 AM
Re: Setting Environment variable in UNIX Shell
thank you all for the reply
I got the solution i.e,
execute the perl script through a shell script and write all the env variables into a file and execute this file as source i.e. , by . ./Env.sh and also execute the shell script that is executing the Perl script also as source .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2007 01:17 AM
тАО09-28-2007 01:17 AM
Re: Setting Environment variable in UNIX Shell
By the way:
You don't need to turn the executable bit on to source (read) a file as you showed in your example, above.
Also: If you are using the HP-UX POSIX shell (the standard one) you need to use the dot-space-filename notation to source. If you are using the 'bash' shell, your 'source' notation is fine. NEVER change 'root's shell from '/sbin/sh' to anything else or risk having a system that will not startup after a boot!!!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2007 06:13 PM
тАО09-28-2007 06:13 PM
Re: Setting Environment variable in UNIX Shell
Solution i found i have already shown in my reply
thanks and regards
Vikram
- « Previous
-
- 1
- 2
- Next »