How to print apparently hidden environment variables?

5,103

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=…
Share:
5,103

Related videos on Youtube

Christopher
Author by

Christopher

Updated on September 18, 2022

Comments

  • Christopher
    Christopher over 1 year

    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?

  • anthony
    anthony almost 8 years
    Unfortunately '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.