The declare command

The declare builtin sets or displays variables (including arrays) and functions. It's not usually needed for setting variables, but it's a good way to get an overview of your shell's current running state, providing more information than the set builtin.

Run with only the -p option, declare prints the values of all of the variables in the current shell environment, along with some short option flags that describe their properties:

bash$ declare -p
declare -- BASH="/bin/bash"
declare -r BASHOPTS="cdspell:checkhash:checkjobs:checkwinsize:...
declare -ir BASHPID
declare -A BASH_ALIASES=()
declare -a BASH_ARGC=()
...

If you include the names of any variables after -p, without the dollar sign prefix, Bash will print results only for those names:

bash$ declare -p BASH PWD
declare -- BASH="/bin/bash"
declare -x PWD="/home/bashuser"

When run with the -f option instead of -p, declare prints any functions defined for your shell. If you have just started with Bash, you may not have any functions defined just yet.

We will learn more about how to use the declare builtin in Chapter 6, Loops and Conditionals.