The env command can be used to print environment variables in bash. I want to ask if there is any built-in command to do this ?

$ export temp="hello world"
$ env | grep temp

The second command will indeed print temp's value, but that's because it is inherited as environment when env was spawned. I want to check what environment variables the bash shell process had originally, in which temp would still not be part of environment , but just marked to be exported as environment for any child (I want to test this).

  • Have you tried set ?
    – steve
    Aug 13, 2015 at 7:37
  • try set -o posix; set
    – gwillie
    Aug 13, 2015 at 7:40
  • @gwillie: It will show the exported variables.
    – cuonglm
    Aug 13, 2015 at 9:12

1 Answer 1


You are right, when exporting or declaring a variable inside a shell, the variable is not added to the shell's environment (in the mean of updating the file - read below).

You can view environment variables of the shell (or any other process) it had when it was invoked, by viewing the /proc/PID/environ file, where PID is the PID of the process you want to analyze. The variables there are saved in the classic form var=value and are separated by null character.

  • I have two shell scripts cmdline and environ, which just do tr '\0' '\n' <<</proc/${pid}/cmdline (figure out the second one).
    – ott--
    Aug 13, 2015 at 20:01
  • Sorry, one < only instead of <<<.
    – ott--
    Aug 13, 2015 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.