How to print apparently hidden environment variables?
Solution 1
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)
Solution 2
There are no hidden environment variables.
All are printed with either env
or printenv
.
What you did was print the value of a variable EUID
, but that variable is not exported.
$ bash -c 'declare -p EUID'
declare -ir EUID="1000"
That is: (i
) for integer and (r
) for readonly. No (x
) for exported, though.
$ zsh -c 'typeset -p EUID'
typeset -i10 EUID=1000
That is (i
) for integer, (10
) for base 10 (decimal).
Instead:
$ bash -c 'declare -p PATH'
declare -x PATH="…"
$ zsh -c 'typeset -p PATH'
export PATH=…
Related videos on Youtube
Christopher
Updated on September 18, 2022Comments
-
Christopher over 1 year
Environment variables can be shown with
env
; but, some are not shown. For example...echo $EUID
might produce as result of1000
yetenv | 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?
-
Lesmana about 11 yearssee also: unix.stackexchange.com/questions/3510/…
-
chepner about 11 yearsNot all shell variables are environment variables, only those that are marked for export by, e.g., the
export
command. -
Eliah Kagan over 6 yearsRelated (on Ask Ubuntu): Why aren't variables like $PS1 in printenv?
-
-
anthony almost 8 yearsUnfortunately 'set' can add quotes while 'env' does not as such this will list some variables (often very long ones), which are actually exported environment variables.