This is overly complex.  The initial setting of env var EVR at the beginning of 
the script does nothing, and the C program is just using the environment to 
store a temp value, which isn't even needed.  The usage of a file is also 
unnecessary (unless you want to retain the value).

This would do the same thing...
        #!/bin/sh
        EVR=`./your_c_program`

Or in csh
        #!/bin/csh
        setenv EVR `./your_c_program`

With the C program being
        printf("%d", int_value);
or
        printf(string_value);
or whatever needs to be set in the env var.

- Rob

> -----Original Message-----
> From: 
> davinci-linux-open-source-bounces+rtivy=ti....@linux.davincids
> p.com 
> [mailto:davinci-linux-open-source-bounces+rtivy=ti....@linux.d
> avincidsp.com] On Behalf Of Sander Huijsen
> Sent: Thursday, December 18, 2008 6:08 AM
> To: davinci-linux-open-source@linux.davincidsp.com
> Subject: RE: A way to export from c an environment var
> 
> Well yes, Arie, you are right about that. I did find a 
> clever/nasty (you be the judge of that) solution for the 
> problem. Simply write the environment variable from within 
> your application to a file, and then "source" the file in 
> your script. :-)
> 
> The script might look something like this:
> 
> [script]
>       #!/bin/sh
> 
>       # create some environment variable 'EVR' and show it
>       EVR="your value"
>       echo $EVR
> 
>       # run your C program, which changes EVR and exports it 
> to /tmp/evr.env
>       ./your_c_program
> 
>       # source the changed environment
>       source /tmp/evr.env
> 
>       # now show the changed value
>       echo $EVR
> 
>       # and exit the script.
>       exit 0
> [/script]
> 
> 
> In your C program, you would do something like this: 
> 
> [snippet]
>       // Here, you change the environment variable
>       setenv("EVR", "my changed value", 1);
> 
>       // Open a temp file to write the environment variable in
>       FILE *fh = fopen("/tmp/evr.env", "w+");
>       if (fh)
>       {
>               // This will write 'EVR="my changed value"' in 
> the temp file
>               fprintf(fh, "EVR=\"%s\"\n", getenv("EVR"));
>               fclose(fh);
>       }
> [/snippet]
> 
> 
> Regards,
> Sander
> 
> 
> -----Original Message-----
> From: Arie de Muijnck [mailto:leon...@ademu.com]
> Sent: Thursday, December 18, 2008 10:52 AM
> To: Sander Huijsen; davinci-linux-open-source@linux.davincidsp.com
> Subject: Re: A way to export from c an environment var
> 
> Unless one wants to set a persistant value, that can be used 
> after his/hers process finishes...
> 
> Unfortunately functions like setenv(), putenv(), 
> system("export ...") change only the current environment of 
> the process itself, not the 'global'
> environment of the user (let alone the system).
> 
> Regards,
> Arie de Muijnck
> 
> ----- Original Message ----- 
> > You might want to try setenv(). Just type 'man 3 setenv' in a Linux 
> > shell to get the man-page for that function (which is in stdlib).
> >
> > Sander
> >
> >
> > -----Original Message-----
> > Hi,
> >
> > Is there a way to create and export from c an environment 
> variable a 
> > bash script can be aware of? I intend something like PATH, etc.
> >
> > Thanks and Regards,
> >
> > VanVliet
> >
> > Dr. Caroline Van Vliet
> > Adfl Group
> > Advanced DSP Flexible Language Group
> > Via Greto di Cornigliano 6R
> > 16152 - Genova, Italy
> > Tel. +39 010 8609370 - Fax +39 010 8609381
>   
> --------------------------------------------------------
> 
>  
> CONFIDENTIALITY NOTICE - This e-mail transmission, and any 
> documents, files or previous e-mail messages attached to it 
> may contain information that is confidential or legally 
> privileged. If you are not the intended recipient, or a 
> person responsible for delivering it to the intended 
> recipient, you are hereby notified that you must not read 
> this transmission and that any disclosure, copying, printing, 
> distribution or use of any of the information contained in or 
> attached to this transmission is STRICTLY PROHIBITED. If you 
> have received this transmission in error, please immediately 
> notify Sander Huijsen by telephone or 
> shuij...@optelecom-nkf.com and delete the original 
> transmission and its attachments without reading or saving in 
> any manner.
> 
> _______________________________________________
> Davinci-linux-open-source mailing list
> Davinci-linux-open-source@linux.davincidsp.com
> http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
> _______________________________________________
Davinci-linux-open-source mailing list
Davinci-linux-open-source@linux.davincidsp.com
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to