Well, the problem is when you run a perl script, it runs as a child process of the shell you call it from, so changes to the child don't take place in the parent. The only way that I would know of would be to actually add them to the .bash_profile or .mycshrc file, so they are automatically set, but that's kind of a permanant thing, and still doesen't work for your problem, because you have to restart the shell.
You may be able to fake it with an exec or system or backtick call to a shell with setenv...., but this may create yet another sub-shell. You'll have to read the docs to see if one of these calls actually uses the shell you are running the script from. I hope that makes sense, if not, let me know and I"ll explain further. As always, I hope that helped!
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
You could also try exporting the environment variables after you set them. This works on some *nix systems, not sure which. Export is an *nix command, so check the man pages for your system.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
Actually, it doesn't explain why. Isn't the purpose of the export command to export environment variables from a sub-shell to the main shell? Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
That means that when THAT SCRIPT starts a subshell the variable MYVAR will be visible to the subshell.
It does not mean that the program that called your script will able to see MYVAR.
You can't, as far as I know, do what the OP wanted. However.... You *can* do this:
[tt]
$ENV{'var_one'} = 'hello';
$ENV{'var_two'} = 'goodbye';
system('some_command');
[/tt]
the program 'some_command' will then have access to the variables var_one and var_two. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
What I meant was to use the system command to set and export the environment variables. Use the semicolon, or whatever your flavor of *nix uses to separate commands and put the set commands and the export commands in the same command line. It's worth a try.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
Have a go ts, don't *think* that will work -- here's why I think so.
The system() function starts a subshell, a child process. This child process only last as long as the system() function lasts and, when it finishes, any variables it sets or changes will disappear unless it leaves child processes of its own.
I like your sig by the way <smile> Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
Thanks, I borrowed it from somewhere, and changed catsup to mustard (I hate catsup).
I know system starts a child process (or subshell), but my understanding is that the export command is supposed to "export" the named environment variable(s) from the subshell to the "main" shell environment. Tomorrow morning I'll check the man page for export, and maybe even try it out from perl to see how it works.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
catsup..... sounds horrible, if I knew what it was I'm sure I'd hate it.... Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
"export ...... functions to determine the characteristics for the environmental variables of the current shell and its descendents."
BTW - Is it dangerous to stand behind a dragon? Seems like it might be if he has had to much mustard? <yuk-yuk-yuk> Or, is that how they fly????
.... Sorry, I'm a connoiseur of poor humor.
That description from the SunOS man page isn't real helpful, but since it says "descendents" it may not export to the "main" shell. I'll have to try it out and see what happens.
Now that I've post ON topic...
Catsup is an alternative spelling of ketchup. You know, that nasty tomato and water stuff that Ronald Reagan thought should qualify as a vegetable in school lunches.
It's only dangerous to stand behind a dragon if he has been eating hot mustard. Salsa, jalapenos and Tabasco sauce are even more dangerous. (In dragon talk we call those "jet fuel".)
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.