Another thing, whenever the program exits, variable PATH regains its previous value. But for PS1, I want to keep the prompt changed as long as the shell runs. How can I do that?
Sorry, I misunderstood your original request. You cannot do this in unix, it is not possible.
OK, this is a common problem that many new users unfamiliar with unix processes seem to have. It's straightforward once you get the hang of it though.
Every process inherits its environment from its parent process. That is, it gets a _copy_ of the parent's environment. The child can change its own environment any way it likes but it *cannot*, ever, in any way, affect the parent's environment. That is why variables return to their original value once the program exits. In fact, they don't really "return" to the old value, because they never really changed, all your process did was change its own copy of the variable, the variable in the parent's environment did not change.
A good book or tutorial on unix programming will explain this in more detail.
Variable PS1 has no value
If PS1 has no value, then it has no value. Assuming PS1 is set to something in your shell, which presumably it is, the only logical conclusion I can think of is that PS1 is not being exported. Environment variables can be local to the shell (a bit like a local variable in a C function, which can't be accessed from other functions, or in this case, processes) or exported, which means that it will be passed in the environment to child processes. Put 'export PS1' somewhere in your ~/.bashrc (or the appropriate rc file if you don't use bash), that should fix it.
If you want to change PS1 (or any other variable) in the shell, then the shell must change it itself, as explained above, other programs cannot do this. I.e. use a shell function or an alias or *source* (not run in a sub-shell) a shell script.