How to change the value of PS1 from within a c program

V

vatsa

Hi all,

we can simply change value of PS1 from command prompt .
but I want to change the value of PS1 from within a c program. i tried
to
do that using getenv & putenv. but it is n't working... .
i even wrote 1 code to print all environment variables, among them PS1
wasn't there. but when i use "set" command on command prompt, it
displays PS1 too among other environment variables...


how to do it ?


regards
rahul
 
W

Walter Roberson

we can simply change value of PS1 from command prompt .

Perhaps on whatever system you are using, but the C language standard
does not know about any "command prompt" or any "PS1".
but I want to change the value of PS1 from within a c program. i tried
to do that using getenv & putenv. but it is n't working... .
i even wrote 1 code to print all environment variables, among them PS1
wasn't there. but when i use "set" command on command prompt, it
displays PS1 too among other environment variables...
how to do it ?

The C language standard does not assign meaning to any environment
variable or to the effect on the system of setting any particular
environment variable. Your question is thus really a question
specific to whatever operating system you are using; you should
ask in a more appropriate newsgroup.


<OT>
1) In Unix, setting an environment variable in a program only
affects subshells and never the shell that invoked the program.
Thus in Unix, what you want to do is not possible.

2) If PS1 does not appear amongst the environment variables, it
could be that it is a local environment variable. In the Bourne
family of shells (e.g., sh, ksh, bash), environment variables
must be "exported" in order to become available to subprocesses.
In the cshell family, this is expressed by "set" vs "setenv".

3) Shells usually offer a mechanism to execute a program and to
interpret the program output as a series of environment
variable settings. One of the more common syntax notations for
that is to use backquotes around the program invocation.
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

vatsa said:
Hi all,

we can simply change value of PS1 from command prompt .
but I want to change the value of PS1 from within a c program. i tried
to
do that using getenv & putenv. but it is n't working... .
i even wrote 1 code to print all environment variables, among them PS1
wasn't there. but when i use "set" command on command prompt, it
displays PS1 too among other environment variables...


how to do it ?
comp.unix.programmer is the place to ask.

Do remember that the PS1 is a shell variable.
Your program is a child of the shell. You cannot
change the parents environment.
 
K

Keith Thompson

(e-mail address removed)-cnrc.gc.ca (Walter Roberson) writes:
[...]
2) If PS1 does not appear amongst the environment variables, it
could be that it is a local environment variable. In the Bourne
family of shells (e.g., sh, ksh, bash), environment variables
must be "exported" in order to become available to subprocesses.
In the cshell family, this is expressed by "set" vs "setenv".

Non-exported variables aren't referred to as "environment variables",
and "local environment variable" is a contradiction. The distiction
is between "environment variables" and "shell variables".

comp.unix.shell is a more appropriate place for this -- but I think
it's a FAQ there.
<OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top