473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Adding ENV variables in linux

I was writing a perl program where I have to add one environment variable.
like RCS_ROOT.
I tried to use system( " setenv RCS_ROOR ****");
i also tried system(" export RCS_ROOT=********");
But nothing is working .. when i run it tell no file called setenv.
Please let me know how to set userdefined env. using perl.
Basic idea is set some user defined paths with setup script
and later use those paths in diff. scripts to locate files.

please help

regards
vijay
Feb 27 '07 #1
8 10940
arne
315 Expert 100+
You may want to have a look at the %ENV hash. In this hash Perl maintains the environment variables.
Feb 27 '07 #2
KevinADC
4,059 Expert 2GB
I'm pretty sure he got the answer on another forum.
Feb 27 '07 #3
No I have not found any answer!!
well I tried to manipulate %ENV but %ENV contains list of only existing variables
but I want to add new variable which does not exist...
Feb 28 '07 #4
KevinADC
4,059 Expert 2GB
maybe:

$ENV{RCS_ROOT} = "your value here";

only works for the duration of the script though. If you need it to be persistent write it to a file and read the file each time the script is envoked. Maybe somone else knows a better way.
Feb 28 '07 #5
thanks kevin this will solve the problem but still my doubt is why system does not execute the setenv?
I tried to write shell script and then execute the script even with that I am not able to see the variable added or set !!!!!
well I wil try to do by ur method.....


thanks

maybe:

$ENV{RCS_ROOT} = "your value here";

only works for the duration of the script though. If you need it to be persistent write it to a file and read the file each time the script is envoked. Maybe somone else knows a better way.
Feb 28 '07 #6
miller
1,089 Expert 1GB
First off, it sounds like you should simply create a file to save these settings in. That is the best way to ensure that the settings are persistant. Then you simply have any of your subsequent scripts import the data. You could even still use the $ENV variables method.

For example, say that this was your settings file. ".settings"
Expand|Select|Wrap|Line Numbers
  1. $ENV{RCS_ROOR} = "your value here";
  2.  
Then all scripts that needed this value could simply import it by doing an eval or require. Then simply access the data using the environment variable.

Expand|Select|Wrap|Line Numbers
  1. require ".settings";
  2.  
  3. print "$ENV{RCS_ROOR}";
  4.  
If you do not need persistance, then making a simple assignment like in Kevin's example would work fine.

Concerning why setenv and export do not work. This is something that I've attempted before and eventually abandoned as a bad approach. Basically, my understanding is that setenv and export are something that is specific to the shell environment thatyou are using, whether it's tsh or bash, etc. You could try to do a system("bash export foo='bar'") call, but that would only last for that one statement. The only way to effect all subsequent shell environments is to add the export call to the .bashrc or .tcshrc start routine. And even then, that's not going to effect any shell environments that are already spawned.

Anyway, the moral of the story is to not rely on the environment that you're running perl under to set configuration data for other perl scripts. Instead create a configuration directory or file that all the scripts can share. Or if you simply need it for one session, use the method that Kevin suggests.

- Miller
Feb 28 '07 #7
Thank you Miller for help
I dropped Idea of setting environment variables with perl script because I dont want setup script to be dependent on any other file or any other scripts to be dependent on other files. ( that was the reason I wanted to set env. variables )
Now for setup I am using shell scripting.
Like we source .bash or .cshrc when we login we can source this setup file everytime we login. and everything is working fine with this setup.


thanks again
vijay
Mar 2 '07 #8
miller
1,089 Expert 1GB
That can work, and is pretty much the only way to do it using ENV variables. I would simply like to point out that you are still dependent on an external file, be it somewhat transparently.

Anyway, glad you found a solution that you're happy with.

- Miller
Mar 2 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: surrealtrauma | last post by:
the requirement is : Create a class called Rational (rational.h) for performing arithmetic with fractions. Write a program to test your class. Use Integer variables to represent the private data...
1
by: John Ratliff | last post by:
Do I have to declare store in my implementation file for all static member variables, even when they are const ints? In Windows, using msys with g++ 3.4.2 and whatever linker I'm not sure...
4
by: David Link | last post by:
Hi, Why does adding SUM and GROUP BY destroy performance? details follow. Thanks, David Link s1.sql: SELECT t.tid, t.title, COALESCE(s0c100r100.units, 0) as w0c100r100units,
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
5
by: Daz | last post by:
Hi Everyone. Please could someone explain how I can go about adding separate member functions to stock.add? For example, stock.add.count(int) and stock.add.value(int)? This way I can hopefully...
18
by: MajorSetback | last post by:
I am using the Redhat version of Linux and GNU C++. It is not clear to me whether this is a Linux issue or a C++ issue. I do not have this problem running the same program on Windows but...
3
by: iwl | last post by:
Hello, I would like to add Variables to my embedded python which represents variables from my C++-Programm. I found C-Api-funcs for adding my C-Funcs to python but none to add variables. I...
6
by: Alfred | last post by:
On Ubuntu, I've been experimenting with Kazuho Oku's fascinating Linux- based perl/C trick to implement C and C++ as a scripting language... ...
1
by: smartchap009 | last post by:
Adding,Updating and Deleting user using perl script in linux -------------------------------------------------------------------------------- hi, If i can get help in writing perl code for...
25
by: sidd | last post by:
In the following code: int i = 5; ---it goes to .data segment int j; ---it goes to bss segment int main() { int c; int i = 5; ---stack
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.