Bash – How to print apparently hidden environment variables

bashenvironment-variableslinuxzsh

Environment variables can be shown with env; but, some are not shown. For example…

echo $EUID might produce as result of 1000 yet
env | grep EUID produces no result.

What is this type of variable? A read-only environment variable?

Do all shells set the same variables by some convention?

How does one go about listing these hidden variables?

Best Answer

The set command shows all variables (and functions), not just the exported ones, so

set | grep EUID

will show you the desired value. This command should show all the non-exported variables:

comm -23 <(set | grep '^[^=[:space:]]\+=' | sort) <(env | sort)