Ubuntu – Why aren’t variables like $PS1 in printenv

bashcommand lineenvironment-variablesps1

From what I can tell printenv displays environment variables, but why don't I see other variables like PS1 for customizing the shell prompt?

What exactly is printenv outputting and why doesn't it pick up PS1? Is there a more comprehensive output command that does more than printenv?

Best Answer

That's because PS1 is not normally exported.

Environment variables are used to set the execution environment of child processes; since PS1 only really has significance within an interactive shell, there's not normally any point exporting it - it is just a plain shell variable.

If you start an interactive child shell, then it will read and set its PS1 from the shell's resource file such as ~/.bashrc

If you export PS1 then you will see it in the printenv output. Alternatively you can see plain shell variables using the bash builtin set as described here How to list all variables names and their current values?