Environment

Environment

Post by Filipe Bonjou » Tue, 08 Aug 2000 04:00:00



Hi,

I wanted to write a small C program to append or remove directories
to/from variables such as PATH or MANPATH, in such a way that a dir-
ectory only appears in the variable once. I remember from my Solaris
days that there was a command (CkPath, or something similar), so it
should be possible to do (it was an ELF binary, not a shell script).

The problem is that when the C program returns the variables are
unchanged. I think that this is because the program is run in a
private shell rather than the calling shell, so all changes only
apply to the private shell and are discarded on exit.

Does anyone know the best way to change the environment variables of
the calling shell from a C program (if there is one)? Otherwise, is
it possible to do with a shell script?

Thnks,

Fil

 
 
 

Environment

Post by Nate Eldredg » Tue, 08 Aug 2000 04:00:00



> Hi,

> I wanted to write a small C program to append or remove directories
> to/from variables such as PATH or MANPATH, in such a way that a dir-
> ectory only appears in the variable once. I remember from my Solaris
> days that there was a command (CkPath, or something similar), so it
> should be possible to do (it was an ELF binary, not a shell script).

> The problem is that when the C program returns the variables are
> unchanged. I think that this is because the program is run in a
> private shell rather than the calling shell, so all changes only
> apply to the private shell and are discarded on exit.

> Does anyone know the best way to change the environment variables of
> the calling shell from a C program (if there is one)? Otherwise, is
> it possible to do with a shell script?

Either:

- Use a shell script, and call it with `source';
- Write a program that outputs the necessary shell commands
  (i.e. printf("export FOO=BAR")), then have
  the shell run it with

eval `myprog`

--

Nate Eldredge


 
 
 

Environment

Post by Nate Eldredg » Tue, 08 Aug 2000 04:00:00



> Hi,

> I wanted to write a small C program to append or remove directories
> to/from variables such as PATH or MANPATH, in such a way that a dir-
> ectory only appears in the variable once. I remember from my Solaris
> days that there was a command (CkPath, or something similar), so it
> should be possible to do (it was an ELF binary, not a shell script).

> The problem is that when the C program returns the variables are
> unchanged. I think that this is because the program is run in a
> private shell rather than the calling shell, so all changes only
> apply to the private shell and are discarded on exit.

> Does anyone know the best way to change the environment variables of
> the calling shell from a C program (if there is one)? Otherwise, is
> it possible to do with a shell script?

Either:

- Use a shell script, and call it with `source';
- Write a program that outputs the necessary shell commands
  (i.e. printf("export FOO=BAR")), then have
  the shell run it with

eval `myprog`

See also the comp.unix.programmer FAQ

--

Nate Eldredge

 
 
 

Environment

Post by Pete Zaitc » Tue, 08 Aug 2000 04:00:00


Quote:> Does anyone know the best way to change the environment variables of
> the calling shell from a C program (if there is one)? Otherwise, is
> it possible to do with a shell script?

A child process cannot affect environment on its parent.
The program you saw on Solaris was probably spawning a new shell.
Sun's "ws" program works in that way.

--Pete

 
 
 

1. Why does the cgi environment not inherit environment variables?

When using apache it normally inherits the environment in which it was
started and keeps this environment for executing cgi scripts. For example:
if root has oracle environment variables such as ORACLE_SID set when
starting the server then these are normally available to cgi scripts when
they execute much like the path is. However sometimes and specifically this
time they are not. Could someone explain how this works? It seems to be
somewhat random to me. I've had situations where various instances of the
server had different paths than others.

I'm running apache 1.3.4 and apache 1.3.6 on solaris 2.7 with mod_perl 1.18
and 1.19 respectively.

Matt

2. wu-ftpd 2.4 anonymous user setup problems

3. how to export shell environment variables to the primary environment?

4. Is it possible to make multi-thread socket server program?

5. pick script in The UNIX Programming Environment (The UNIX Programming Environment )

6. ppp dialup

7. Changing Desktop Environments (Window Managers) & Performance of Desktop Environments

8. Problems with ESS1938

9. Can the QA environment be configured with one host if the production environment has two hosts in a HACMP fail over configuration ?

10. "NT IS NOT AN ENTERPRISE ENVIRONMENT" but OS/2 Warp Server is (was :Re: "NT IS NOT AN ENTERPRISE ENVIRONMENT"- Microsoft and HP: Beyond the Hype)

11. C++ development environment

12. 2.x mod_ssl X.509 DN environment variable attributes

13. Need help to choose delvelopment environment