Get all environment variables linux

How to list all Linux environment variables including LD_LIBRARY_PATH

How to list all the environment variables in Linux? When I type the command env or printenv it gives me lots of variables, but some variables like LD_LIBRARY_PATH and PKG_CONFIG don’t show up in this list. I want to type a command that list all the environment variables including this variables ( LD_LIBRARY_PATH and PKG_CONFIG )

3 Answers 3

env does list all environment variables.

If LD_LIBRARY_PATH is not there, then that variable was not declared; or was declared but not export ed, so that child processes do not inherit it.

If you are setting LD_LIBRARY_PATH in your shell start-up files, like .bash_profile or .bashrc make sure it is exported:

export LD_LIBRARY_PATH=/usr/local/lib:$

This will modify the variable.

To print it, type: echo $LD_LIBRARY_PATH and it should show the above value.

If you’re seeing nothing when you print that, then the variable might not be set.

The question in fact is a good question. when run env or printenv , the output will be the system environment, but LD_LIBRARY_PATH is not belong to.

For example, if you set a=1 , you can’t show it by env . Same as LD_LIBRARY_PATH, it is used by ld.so only(ld. so – this little program that starts all your applications)

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Читайте также:  Установка vpn server linux

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

What are my environment variables? [closed]

Wow that was fast! I guess all the command do the trick. The export command gave me a lot of «declare -x» in front. Thanks guys!

It was inappropriate to close this question as off topic. When programming on Linux, as I am doing at the moment, it is often useful to discover what the environmental variables are. Quite a lot of people have found this to be a useful question, including me.

4 Answers 4

I am not sure if thats what you want, but try printenv
This will show you all your environment variables.

Just execute env in a terminal.

$ env TERM=xterm SHELL=/bin/bash USER=joksnet USERNAME=joksnet DESKTOP_SESSION=gnome PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games PWD=/home/joksnet GDM_KEYBOARD_LAYOUT=us LANG=en_US.utf8 HOME=/home/joksnet DISPLAY=:0.0 COLORTERM=gnome-terminal _=/usr/bin/env 

Type export without any parameters.

SET(P) POSIX Programmer’s Manual SET(P) NAME set - set or unset options and positional parameters SYNOPSIS set [-abCefmnuvx][-h][-o option][argument. ] set [+abCefmnuvx][+h][+o option][argument. ] set -- [argument. ] set -o set +o DESCRIPTION If no options or arguments are specified, set shall write the names and values of all shell variables in the collation sequence of the current locale. Each name shall start on a separate line, using the format: "%s=%s\n", , The value string shall be written with appropriate quoting; see the description of shell quoting in Quoting . The output shall be suitable for reinput to the shell, setting or resetting, as far as possible, the variables that are currently set; read-only variables cannot be reset. 

env or printenv are better. In bash, set will also print all your defined functions, which on a system like ubuntu, is a very long printout.

Читайте также:  Install python in linux centos

Источник

How do I see a list of all currently defined environment variables in a Linux bash terminal?

In a Linux bash terminal, there are often many environment variables that have been set, like $PATH and $HOME . Is it possible to see all of the environment variables that have been set? How?

5 Answers 5

TL;DR: use (set -o posix ; set)

According to the Bash manual you can use the set built-in command to show all of the environment variables that have been set. The set command will also display the definitions of any functions. If you only want to see the variables, and not the functions, then you can turn on POSIX mode before running the set command. The easiest way to do that is with set -o posix , but that will leave POSIX mode on until you turn it off with set +o posix .

Therefore, the following command will show all of the defined environment variables by using a subshell without affecting POSIX compliance in your current shell.

@RedGrittyBrick and @iglvzx suggested using the env command, however this command will not provide a complete listing of environment variables. env will only show the varaibles that have been marked for export. Compare the output of env | sort and export -p and you will see what I mean. You can run comm -23 <(set -o posix; set) <(env|sort) if you want to see which environment variables are not being exported.

The reason for the discrepancy is that env is a separate executable as opposed to set which is a shell built-in command. According to the Bash manual, when a command is executed that is not a shell built-in command or function it will only receive environment variables that have been marked for export in Bash. There are many variables that are not exported. Therefore, if you wish to see all of the variables that your shell has defined, you must use the set command as stated in the manual.

Читайте также:  Arch linux или windows

You can easily test this behavior for yourself using the following commands.

MY_TEST_VARIABLE="This is my test variable." set | grep MY_TEST_VARIABLE env | grep MY_TEST_VARIABLE 

You will see that set provides output while env does not.

Источник

Оцените статью
Adblock
detector