By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,682 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,682 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Apr 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <11**********************@v46g2000cwv.googlegroups .com>,
vatsa <va*******@gmail.com> wrote:
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.
--
Prototypes are supertypes of their clones. -- maplesoft
Apr 3 '06 #2

P: n/a
vatsa wrote:
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.
Apr 3 '06 #3

P: n/a
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
[...]
<OT>
[...]
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>

--
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.
Apr 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.