Bash – Print Only Defined Variables

bashenvironment-variables

The bash builtin command set, if invoked without arguments, will print all shell and environment variables, but also all defined functions. This makes the output unusable for humans and difficult to grep.

How can I make the bash builtin command set print only the variables and not the functions?

Are there other commands which prints only the shell variables, without the functions?

Note: bash differentiates between shell variables and environment variables. see here Difference between environment variables and exported environment variables in bash

Best Answer

"Are there other commands which prints only the shell variables, without the functions?"

In man bash, in section SHELL BUILTIN COMMANDS (in the set section) it says: "In posix mode, only shell variables are listed."

(set -o posix; set)

note: () syntax spawns a subshell, if you don't like forking just use the more verbose version

set -o posix; set; set +o posix
Related Question