View and add environment variables under Linux

Source: Internet
Author: User

Transferred from: http://blog.sina.com.cn/s/blog_688077cf01013qrk.html

$PATH: determines which directories the shell will look for commands or programs, the value of PATH is a series of directories, and when you run a program, Linux searches for compiled links in these directories.

Edit your PATH declaration in the following format:

Path= $PATH: <path 1>:<path 2>:<path 3>:------: <path n>

You can add the specified path yourself, separated by a colon. When the environment variable is changed, it takes effect the next time the user logs on, and if you want to take effect immediately, you can execute the following statement: $ source. bash_profile

It is important to note that it is best not to put the current path "./" in path, which may be subject to unexpected attacks. When you are finished, you can view the current search path through the echo $PATH. With this customization, you can avoid frequent launches of programs that are outside the path of the shell search.

1. Use the Export command to view the path value

[Email protected] u-boot-sh4]#Export
Declare-x cvs_rsh= "SSH"
Declare-x display= ": 0.0"
Declare-x g_broken_filenames= "1"
Declare-x histsize= "1000"
Declare-x home= "/root"
Declare-x hostname= "localhost"
Declare-x inputrc= "/ETC/INPUTRC"
Declare-x lang= "ZH_CN. UTF-8 "
Declare-x lessopen= "|/usr/bin/lesspipe.sh%s"
Declare-x logname= "Root"
Declare-x ls_colors= "no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi= 01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar= 00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*. z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00 ; 35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35: "
Declare-x mail= "/var/spool/mail/root"
Declare-x oldpwd= "/root"
Declare-xPATH= "/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
Declare-x pwd= "/opt/stm/stlinux-2.3/devkit/sources/u-boot/u-boot-sh4"
Declare-x shell= "/bin/bash"
Declare-x shlvl= "1"
Declare-x ssh_askpass= "/usr/libexec/openssh/gnome-ssh-askpass"
Declare-x term= "Xterm"
Declare-x user= "Root"
Declare-x xauthority= "/root/.xauthkszh7b"

2. View the PATH environment variables separately, as available:

[Email protected] u-boot-sh4]#echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

3. Add the PATH environment variable (temporary), available:

[Email protected] u-boot-sh4]#export path=/opt/stm/stlinux-2.3/devkit/sh4/bin: $PATH

Check again:

[Email protected] u-boot-sh4]# echo $PATH
/opt/stm/stlinux-2.3/devkit/sh4/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin :/bin:/usr/sbin:/usr/bin:/root/bin

Description Add path succeeded.

The path of the above method disappears after the terminal is closed.

4. Permanently add environment variable (affects current user)

#vim ~/.bashrcexport path= "/opt/stm/stlinux-2.3/devkit/sh4/bin: $PATH" 5. Permanently add environment variables (affects all users)# Vim/etc/profile at the end of the document, add:Export path= "/opt/stm/stlinux-2.3/devkit/sh4/bin: $PATH" Save, Exit, and run: # Source/etc/profile

No error is successful.

Questions :

1. Do the experiment, in/etc/profile, ~/.profile, ~/.BASHRC Add new path, restart all have no effect, only use source can, ubunt12.04

Find the cause, ~/.ZSHRC, because the path is re-assigned in ZSHRC without inheriting the previous $path, which causes the path to be re-assigned after the/etc/profile is loaded.

View and add environment variables under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.