In bash, $PS1 and $PS2 are shell variables, not environment variables (at least usually). They are set to default values ββwithin bash independently or explicitly set by the user either interactively or when a script is run, for example .profile or .bashrc .
They cannot be accessed through getenv() , and they are not inherited by forked subprocesses. They are controlled internally by the shell of its own mechanism for shell variables.
If you are writing your own shell, it might make sense to do something like this.
You can see the source code of bash. It's big and complex, but finding PS1 and PS2 can be instructive. (You do not need to use the exact same bash mechanism, most likely you will need something simpler.)
(You can enter export PS1 to turn $PS1 into an environment variable, but that doesn't make much sense for this.)
Keith thompson
source share