Listing variables

After a variable has been assigned a value, you can check it by using printf or echo:

$ today='August 9th'
$ printf '%s\n' "$today"
August 9th

Bash includes a builtin named declare, which can be used with variable names as its argument to show more information about each named variable and its value:

$ declare -p today
declare -- today='August 9th'

In this case, the -- string in the output tells us that there is no special attribute to this variable.

You can list all of the variables currently assigned by leaving out the name:

$ declare -p
declare -- BASH="/bin/bash"
declare -r BASHOPTS="cdspell:checkhash...
declare -ir BASHPID
declare -- PS1="\\u@\\h:\\w\\$ "
...