HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Setting ENV variables using a script
Operating System - HP-UX
1833758
Members
2566
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
10-12-2005 07:36 AM
10-12-2005 07:36 AM
I have a number of environemnt variables that I need to set while in a shell. Rather than type "export ENV_VAR=value" a number of times, I would like to create a script to set these in my active shell.
I created a script but it does not change the active shell. Only the script environment while running.
Thanks,
David Owens
I created a script but it does not change the active shell. Only the script environment while running.
Thanks,
David Owens
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2005 07:43 AM
10-12-2005 07:43 AM
Solution
Hi David,
Simplest way is to create a file like - let's call it env_set
ENV1=xxxxxx
ENV2=yyyyyy
ENV3=zzzzzz
Then source the file as follows:
. /path/to/env_set
Then the vars remain set for that shell & it's children. BUT they cannot be sent back to that shell's parent.
HTH,
Jeff
Simplest way is to create a file like - let's call it env_set
ENV1=xxxxxx
ENV2=yyyyyy
ENV3=zzzzzz
Then source the file as follows:
. /path/to/env_set
Then the vars remain set for that shell & it's children. BUT they cannot be sent back to that shell's parent.
HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2005 07:51 AM
10-12-2005 07:51 AM
Re: Setting ENV variables using a script
Hi David:
You simply want to "source" or read a file of the variables you want into your script. You "source" (read) a file with a dot-space character combination before a filename:
. file_to_source
Thus:
# cat /tmp/my.vars
var1="hello"
var2="bye"
# cat /tmp/my.sh
#!/usr/bin/sh
. /tmp/my.vars #...that is DOT-SPACE /tmp...
echo "I said ${var1} and then ${var2}"
exit 0
Now run /tmp/my.sh and you will see that the variables var1 and var2 are in that environment.
Regards!
...JRF...
You simply want to "source" or read a file of the variables you want into your script. You "source" (read) a file with a dot-space character combination before a filename:
. file_to_source
Thus:
# cat /tmp/my.vars
var1="hello"
var2="bye"
# cat /tmp/my.sh
#!/usr/bin/sh
. /tmp/my.vars #...that is DOT-SPACE /tmp...
echo "I said ${var1} and then ${var2}"
exit 0
Now run /tmp/my.sh and you will see that the variables var1 and var2 are in that environment.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2005 07:59 AM
10-12-2005 07:59 AM
Re: Setting ENV variables using a script
Thanks all!
The DOT-SPACE is what I needed.
David
The DOT-SPACE is what I needed.
David
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP