On my search for a command to list all shell variables, I somehow realized, that there is a command to list all environment variables, but somehow there is no one to list all shell variables, for reasons unknown to me. However, someone here gave an answer on how to display all variables, shell and environment ones.( set -o posix ; set ) | lessHe actually did not explain for the layman what this expression does, and my fragmentary understanding is not enough to grasp the idea behind it.This is what I know:( command1; command2) this causes the commands to be executed inside a child process of the shell.set is some way to declare variables, though do not know what the -o posix means and why a second set is executed in successioncommand | less This one is not the problem, even I understand it, it is a pager for more control about the output.
What is ( set -o posix ; set ) | less  doing?
shell;environment variables;subshell;set
set shows all shell variables (exported or not). In Bash, set -o posix sets the shell in POSIX compatibility mode. (I don't know if other shells have similar syntax for the similar feature, but I'll assume Bash here.)The difference in this case is that usually Bash's set shows also shell functions, but in POSIX mode set only shows variables, and changes the output format slightly:When the set builtin is invoked without options, it does not display shell function names and definitions.   When the set builtin is invoked without options, it displays variable values without quotes, unless they contain shell metacharacters, even if the result contains nonprinting characters.In Bash, there's additionally the declare builtin that can be used to show all the otherwise hidden or Bash-specific flags of variables: declare -p xx shows variable xx in a format that Bash can take as input. declare -p shows all variables and declare -f can be used to show functions.