Get the App
SLTechnology News&Howtos  ›  Development  › 

How to view environment variables under Linux

Shulou Source: shulou.com Published: 2022-06-01 20:51:58 09月17日 Update

This article is about how to view environment variables under Linux. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Environment variables are equivalent to "shortcut keys," specifying a directory that the program will look for when running the software

1. Linux View Environment Variables Display Environment Variables HOME

$ echo $HOME/home/redbooks2. Linux View environment variables Set a new environment variable hello

$ export HELLO="Hello! " $ echo $HELLO Hello! 3. Linux View environment variables Use env command to display all environment variables

$ env HOSTNAME=redbooks.safe.org PVM_RSH=/usr/bin/rsh SHELL=/bin/bash TERM=xterm HISTSIZE=1000 …4. Linux View environment variables Use the set command to display all locally defined Shell variables

$ set BASH=/bin/bash BASH_VERSINFO=([0]="2″[1]="05b"[2]="0″[3]="1″[4]="release"[5]="i386-redhat-Linux-gnu") BASH_VERSION=’2.05b.0(1)-release’ COLORS=/etc/DIR_COLORS.xterm COLUMNS=80 DIRSTACK=() DISPLAY=:0.0 …5. Linux View environment variables Use the unset command to clear the environment variable set to set the value of an environment variable. Clear the value of an environment variable with the unset command. If no value is specified, the variable value is set to NULL. Examples are as follows:

$ export TEST="Test…" #Add an environment variable TEST $ env| grep TEST #This command has input, proving that the environment variable TEST already exists TEST=Test… $ unset $TEST #Delete the environment variable TEST $ env| grep TEST #This command has no output, proving that the environment variable TEST already exists 6. Linux View environment variables Use readonly to set readonly variables If readonly is used, variables cannot be modified or cleared. Examples are as follows:

$ export TEST="Test…" #Add an environment variable TEST $ readonly TEST #Set the environment variable TEST to readonly $ unset TEST #You will find that this variable cannot be deleted-bash: unset: TEST: cannot unset: readonly variable $ TEST="New" #You will find that this variable cannot be modified-bash: TEST: readonly variable The setting of the environment variable is located in the/etc/profile file

Thank you for reading! About "how to view environment variables under Linux" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Variables environment commands content files more directories examples articles good practical shortcut keys articles times look knowledge programs software values references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology NVidia Apple macOS