Skip to main content
deleted 74 characters in body
Source Link
Andy Dalton
  • 14.7k
  • 1
  • 28
  • 50

You can examine /proc/${pid}/environ. That contains the process' environment, and I haven't see a case where the shell updates that as theinitial environment changes.

Here, $$ is the pid of the running shell. Note also that the variables are nil-character delimited. The -e option to cat will cause it to print non-printable characters (like the nil character), and the sed converts the representation of the nil characters to newlines.

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0

$ export DISPLAY=broken

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0

You can examine /proc/${pid}/environ. That contains the process' environment, and I haven't see a case where the shell updates that as the environment changes.

Here, $$ is the pid of the running shell. Note also that the variables are nil-character delimited. The -e option to cat will cause it to print non-printable characters (like the nil character), and the sed converts the representation of the nil characters to newlines.

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0

$ export DISPLAY=broken

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0

You can examine /proc/${pid}/environ. That contains the process' initial environment.

Here, $$ is the pid of the running shell. Note also that the variables are nil-character delimited. The -e option to cat will cause it to print non-printable characters (like the nil character), and the sed converts the representation of the nil characters to newlines.

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0

$ export DISPLAY=broken

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0
Source Link
Andy Dalton
  • 14.7k
  • 1
  • 28
  • 50

You can examine /proc/${pid}/environ. That contains the process' environment, and I haven't see a case where the shell updates that as the environment changes.

Here, $$ is the pid of the running shell. Note also that the variables are nil-character delimited. The -e option to cat will cause it to print non-printable characters (like the nil character), and the sed converts the representation of the nil characters to newlines.

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0

$ export DISPLAY=broken

$ cat -e "/proc/$$/environ" | sed 's/\^@/\n/g' | grep DISPLAY
DISPLAY=:0.0