When we print the value of PS1
, it is set:
$ echo $PS1
[\u@\h \W]\$
We can use env
command to print environment variables. Why does it not list PS1
variable ?
$ env | grep PS1
# No output here
The PS1 variable contains the value of the default prompt. It is used to change the looks and environment of the shell command prompt. Different examples of using the PS1 variable have been shown in this tutorial.
You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of your Compose file). Values set in the shell environment override those set in the .env file.
To display the values of environment variables, use the printenv command. If you specify the Name parameter, the system only prints the value associated with the variable you requested.
Because PS1 is not (usually, and in your specific case) an environment variable.
There are many variables set in a bash instance which you can list with:
$ set
BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:…
BASH_ALIASES=()
BASH_ARGC=()
.
.
SHLVL=1
SSH_AGENT_PID=853
SSH_AUTH_SOCK=/tmp/ssh-Ofupc03xWIs7/agent.795
TERM=xterm-256color
But many of them are not environment variables. For example:
$ echo "$PPID"
1062
$ env | grep PPID
You can add variables to the environment by using export
. So PS1 could be set as an environment variable:
$ export PS1
$ env | grep PS1
PS1=\u@\h:\w\$
And a variable could be un-exported by removing its export flag with declare (which will retain the value of the variable, just not exported):
$ declare +x PS1
$ env | grep PS1
$ echo $PS1
\u@\h:\w\$
Or, more drastically, by unset
ing the variable:
$ unset PS1
$ env | grep PS1
In bash, declare
could be used to print the flags of variables:
$ declare -p PS1
declare -- PS1="\${debian_chroot:+(\$debian_chroot)}\\u@\\h:\\w\\\$ "
$ export PS1
$ declare -p PS1
declare -x PS1="\${debian_chroot:+(\$debian_chroot)}\\u@\\h:\\w\\\$ "
Note the -x
set for the variable after it is exported.
Depending on where the variable PS1 is set it can be considered local or environmental (see this post to set environmental).
If it's local then you cannot print it with env. But you can print it with the command set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With