Is it completely impossible in UNIX to push an environment variable to
the parent shell? I would like to do something like this:
main(int argc, char *argv[])
{
char *var;
var = (char *)malloc(1028);
strcpy(var, "VAR=");
strcat(var, argv[1]);
putenv(var);
return(0);
}
The above I just did now on the fly so it may not be perfect but it
will get the idea across. Now once this exits, I want to see this
variable in my environment. Is this possible?
Thank you 13 2992
Jimmy Cracker wrote: Is it completely impossible in UNIX to push an environment variable
to the parent shell? I would like to do something like this:
main(int argc, char *argv[]) { char *var; var = (char *)malloc(1028);
strcpy(var, "VAR="); strcat(var, argv[1]);
putenv(var); return(0); }
The above I just did now on the fly so it may not be perfect but it will get the idea across. Now once this exits, I want to see this variable in my environment. Is this possible?
Thank you
Watch out, you're going to get it from clc's wannabe enforcer Keith
Thompson.
Jimmy Cracker wrote: Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this:
main(int argc, char *argv[]) { char *var; var = (char *)malloc(1028);
strcpy(var, "VAR="); strcat(var, argv[1]);
putenv(var); return(0); }
The above I just did now on the fly so it may not be perfect but it will get the idea across. Now once this exits, I want to see this variable in my environment. Is this possible?
This is more of a Unix question. C does not know anything about shells
and environment variables.
Try comp.unix.programmer
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
TTroy wrote: Jimmy Cracker wrote:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: [...]
Watch out, you're going to get it from clc's wannabe enforcer Keith Thompson.
No, no: My turn! Let me! Meee!
A quick quiz for Jimmy C.: What is the output of the
following program?
#include <stdio.h>
#include <string.h>
static void test(const char *p, const char *q) {
printf ("%s %c= %s\n",
p, strcmp(p, q) ? '!' : '=', q);
}
int main(void) {
test ("C", "UNIX");
test ("comp.lang.c", "comp.unix.programmer");
printf ("Off-topic: ");
test ("What you ask", "possible");
return 0;
}
Answer and advice, all in one neat little package.
--
Eric Sosman es*****@acm-dot-org.invalid
Eric Sosman wrote: TTroy wrote: Jimmy Cracker wrote:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: [...] Watch out, you're going to get it from clc's wannabe enforcer Keith Thompson.
No, no: My turn! Let me! Meee!
A quick quiz for Jimmy C.: What is the output of the following program?
.... snip code ... Answer and advice, all in one neat little package.
I have taken the liberty of reformatting your package:
#define O00 static
#define O0O void
#define O0o test
#define OO0 const
#define OOO char
#define OOo printf
#define Oo0 strcmp
#define OoO int
#define Ooo main
#define o00 return
#include <stdio.h>
#include <string.h>
O00 O0O O0o(OO0 OOO *p, OO0 OOO *q) { OOo ("%s %c= %s\n", p,
Oo0(p, q) ? '!' : '=', q); } OoO Ooo(O0O) { O0o ("C", "UNIX");
O0o ("comp.lang.c", "comp.unix.programmer"); OOo ("Off-topic: ");
O0o ("What you ask", "possible"); o00 0; }
(my id2id package comes in handy here)
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
CBFalconer wrote: Eric Sosman wrote:
TTroy wrote:
Jimmy Cracker wrote:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: [...]
Watch out, you're going to get it from clc's wannabe enforcer Keith Thompson.
No, no: My turn! Let me! Meee!
A quick quiz for Jimmy C.: What is the output of the following program?
... snip code ...
Answer and advice, all in one neat little package.
I have taken the liberty of reformatting your package:
#define O00 static #define O0O void #define O0o test #define OO0 const #define OOO char #define OOo printf #define Oo0 strcmp #define OoO int #define Ooo main #define o00 return #include <stdio.h> #include <string.h>
O00 O0O O0o(OO0 OOO *p, OO0 OOO *q) { OOo ("%s %c= %s\n", p, Oo0(p, q) ? '!' : '=', q); } OoO Ooo(O0O) { O0o ("C", "UNIX"); O0o ("comp.lang.c", "comp.unix.programmer"); OOo ("Off-topic: "); O0o ("What you ask", "possible"); o00 0; }
(my id2id package comes in handy here)
Aw, please do not propagate this further -- in the end some
newbie thinks "Wow, this is kinda cool"... And making it into
the annals of c.l.c as the one who instigated the "O0o" style
is probably not your intention ;-)
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address. Jimmy Cracker wrote:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: [...]
It is possible in unix, but not in C.
See the tset command, and the X11 resize command.
-- glen
glen herrmannsfeldt <ga*@ugcs.caltech.edu> wrote: Jimmy Cracker wrote:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: [...]
It is possible in unix, but not in C.
Please, don't give OT answers. Your answer cannot be cross-verified here.
Eric Sosman's answer contains a hint where this question should
be asked and answers given.
See the tset command, and the X11 resize command.
[OT] I believe your answer is wrong (I haven't seen a *nix system
where a child process could modify the environment of its parent).
The above examples are not appropriate for OP's question; you might
not understand what those commands do.
AFAICT only the shell can change its environment variables; it can
be invoked by a special command, or by other means (eg. a signal).
--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Sorry, I didn't realize. I will go to comp.unix.programmer. I didn't
mean to cause trouble on this group.
Thanks all!
On Sat, 05 Feb 2005 22:55:04 +0100, Michael Mair
<Mi**********@invalid.invalid> wrote: Jimmy Cracker wrote: Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this:
main(int argc, char *argv[]) { char *var; var = (char *)malloc(1028);
strcpy(var, "VAR="); strcat(var, argv[1]);
putenv(var); return(0); }
The above I just did now on the fly so it may not be perfect but it will get the idea across. Now once this exits, I want to see this variable in my environment. Is this possible?
This is more of a Unix question. C does not know anything about shells and environment variables.
Try comp.unix.programmer
Cheers Michael
Jimmy Cracker wrote: Sorry, I didn't realize. I will go to comp.unix.programmer. I didn't mean to cause trouble on this group.
When you get there do not top-post. Your answer belongs after (or
intermixed with) the material to which you reply, with all
non-germane matter snipped out.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
In article <42***************@yahoo.com>, cb********@yahoo.com says... Eric Sosman wrote: TTroy wrote: Jimmy Cracker wrote:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: [...]
Watch out, you're going to get it from clc's wannabe enforcer Keith Thompson.
No, no: My turn! Let me! Meee!
A quick quiz for Jimmy C.: What is the output of the following program? ... snip code ... Answer and advice, all in one neat little package.
I have taken the liberty of reformatting your package:
#define O00 static #define O0O void #define O0o test #define OO0 const #define OOO char #define OOo printf #define Oo0 strcmp #define OoO int #define Ooo main #define o00 return #include <stdio.h> #include <string.h>
O00 O0O O0o(OO0 OOO *p, OO0 OOO *q) { OOo ("%s %c= %s\n", p, Oo0(p, q) ? '!' : '=', q); } OoO Ooo(O0O) { O0o ("C", "UNIX"); O0o ("comp.lang.c", "comp.unix.programmer"); OOo ("Off-topic: "); O0o ("What you ask", "possible"); o00 0; }
(my id2id package comes in handy here)
I wonder if gnu indent will support this...
indent -falconer foo.c :-)
--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Randy Howard wrote: In article <42***************@yahoo.com>, cb********@yahoo.com says... Eric Sosman wrote: TTroy wrote: > Jimmy Cracker wrote: > >> Is it completely impossible in UNIX to push an environment >> variable to the parent shell? I would like to do something >> like this: [...] > > Watch out, you're going to get it from clc's wannabe enforcer > Keith Thompson.
No, no: My turn! Let me! Meee!
A quick quiz for Jimmy C.: What is the output of the following program? ... snip code ... Answer and advice, all in one neat little package.
I have taken the liberty of reformatting your package:
#define O00 static #define O0O void #define O0o test #define OO0 const #define OOO char #define OOo printf #define Oo0 strcmp #define OoO int #define Ooo main #define o00 return #include <stdio.h> #include <string.h>
O00 O0O O0o(OO0 OOO *p, OO0 OOO *q) { OOo ("%s %c= %s\n", p, Oo0(p, q) ? '!' : '=', q); } OoO Ooo(O0O) { O0o ("C", "UNIX"); O0o ("comp.lang.c", "comp.unix.programmer"); OOo ("Off-topic: "); O0o ("What you ask", "possible"); o00 0; }
(my id2id package comes in handy here)
I wonder if gnu indent will support this...
indent -falconer foo.c :-)
works fine (v2.2.9):
[1] c:\c\ohohohs>indent -st ohohoh.c
#define O00 static
#define O0O void
#define O0o test
#define OO0 const
#define OOO char
#define OOo printf
#define Oo0 strcmp
#define OoO int
#define Ooo main
#define o00 return
#include <stdio.h>
#include <string.h>
O00 O0O
O0o(OO0 OOO * p, OO0 OOO * q)
{
OOo("%s %c= %s\n", p, Oo0(p, q) ? '!' : '=', q);
}
OoO
Ooo(O0O)
{
O0o("C", "UNIX");
O0o("comp.lang.c", "comp.unix.programmer");
OOo("Off-topic: ");
O0o("What you ask", "possible");
o00 0;
}
In fact, with the file idpairs (related to the #defines) around:
[1] c:\c\ohohohs>type idpairs
O00 static
O0O void
O0o test
OO0 const
OOO char
OOo printf
Oo0 strcmp
OoO int
Ooo main
o00 return
you can do a complete conversion in one line:
[1] c:\c\ohohohs>indent -st ohohoh.c | id2id
#define static static
#define void void
#define test test
#define const const
#define char char
#define printf printf
#define strcmp strcmp
#define int int
#define main main
#define return return
#include <stdio.h>
#include <string.h>
static void
test(const char * p, const char * q)
{
printf("%s %c= %s\n", p, strcmp(p, q) ? '!' : '=', q);
}
int
main(void)
{
test("C", "UNIX");
test("comp.lang.c", "comp.unix.programmer");
printf("Off-topic: ");
test("What you ask", "possible");
return 0;
}
which is much easier than the gyrations I had to go through to make
it in the first place. :-)
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
On Sun, 06 Feb 2005 13:24:17 +0000, S.Tobias wrote: command, and the X11 resize command.
[OT] I believe your answer is wrong (I haven't seen a *nix system where a child process could modify the environment of its parent).
Such a system would be terminally broken from a security viewpoint.
Lawrence
glen herrmannsfeldt <ga*@ugcs.caltech.edu> writes: Jimmy Cracker wrote:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: [...]
It is possible in unix, but not in C.
See the tset command, and the X11 resize command.
<OT>
Those commands are examples of ways a parent process can set its own
environment variables based in information from a child process. They
do not illustrate propagating an environment variable directly to a
parent process, which is generally not possible in Unix.
</OT>
The only facility C provides is the getenv() function, whose behavior
is almost entirely system-specific. It allows querying a specific
environment variable; there's no portable way either to set a variable
or to get a list of all environment variables. A conforming C
implementation could be perfectly happy on a system on which child
processes can propagate environment variables to their parents, or
even to unrelated processes. The C standard says nothing about
processes at all.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sami Viitanen |
last post by:
Hello,
Is there any other way to set variables than os.putenv().
Putenv doesn't actually put any values to actual system variables..
I'm trying to set CVSEDITOR variable automatically from...
|
by: Greg Lindstrom |
last post by:
Hello-
I am running python 2.3. on an HP-9000 box running Unix and have a POSIX
script that sets up my production environment. I would like to run the
script from inside a python routine and...
|
by: Christian |
last post by:
Another question from a not even newbie:
In Unix you can set an environment variable with the command
export PYTHONPATH
but I would like to set the variable from at .py script.
So my question...
|
by: |
last post by:
Hi all, I am trying to append a certain string to the
PATH environment variable programmatically. I am able to
read what is in the variable using the System.Environment
method...
|
by: strawberry |
last post by:
In the function below, I'd like to extend the scope of the $table
variable such that, once assigned it would become available to other
parts of the function. I thought 'global $table;' would solve...
| |
by: Maxim Veksler |
last post by:
Hello list,
I'm trying to write a python script that would allow me to manipulate
shell variables of the calling shell. I'm trying to write some logic
that would know to add LD_LIBRARY_PATH to...
|
by: Cameron Simpson |
last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote:
Because $HOSTNAME is a bash specific variable, set by bash but NOT
EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses...
|
by: Fredrik Lundh |
last post by:
aditya shukla wrote:
not if you run the script from the shell.
when a process starts, it gets a *copy* of the parent's environment. it
can modify that copy, but it cannot modify the...
|
by: rowen |
last post by:
I'd like to replace some shell scripts with Python, but one step of
the script modifies my environment in a way that the subsequent steps
require.
A simple translation to a few lines of...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |