Linux environment variables

Source: Internet
Author: User
Tags terminates

The difference between BASHRC and profile

To understand the difference between BASHRC and profile, first figure out what is interactive shell and non-interactive shell, what is Loginshell and non-login shell.

The interactive mode is where the shell waits for your input and executes the commands you submit. This pattern is called interactive because the shell interacts with the user. This mode is also familiar to most users: Log in, execute some commands, and check back. When you sign back, the shell also terminates.

The shell can also run in a different mode: non-interactive mode. In this mode, the shell does not interact with you, but instead reads the commands stored in the file and executes them. When it reads the end of the file, the shell terminates.

BASHRC and profile are used to save the user's environment information, BASHRC for interactive Non-loginshell, and profile for interactive Loginshell. There are many BASHRC and profile files in the system, which are described below:

/ETC/BASHRC, what is the difference between BASHRC and the user directory?

One is for all users of the entire system, one for the specific user./ETC/BASHRC modified to restart the system to take effect, and the user directory. BASHRC modified to take effect after re-login

2. What is the difference between/etc/profile and/ETC/BASHRC?

The former is mainly used to set up some system variables, such as java_home and so on, the latter one is mainly used to save some bash settings.

/etc/profile: This file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time.

and collect the shell settings from the configuration file of the/ETC/PROFILE.D directory.

/ETC/BASHRC: Executes this file for each user running Bashshell. When the bash shell is opened, the file is read.

~/.bash_profile: Each user can use this file to enter shell information dedicated to their own use, when the user logs on, the

The file is only executed once! By default, he sets some environment variables to execute the user's. bashrc file.

~/.BASHRC: This file contains bash information dedicated to your Bashshell, when you log on and each time you open a new shell, the

The file is read.

~/.bash_logout: Executes the file each time you exit the system (exit Bashshell).

In addition, the variables set in/etc/profile (global) can be applied to any user, while the variables set in ~/.BASHRC, etc. (local) only inherit variables from/etc/profile, they are "parent-child" relationships.

~/.bash_profile is interactive, login way into bash run

~/.BASHRC is an interactive non-login way into bash run

Usually the two settings are roughly the same, so the former usually calls the latter.

The. bash_profile file is executed at the time of the login (login) system through the console (or Telnet, for example, SSH).

The. BASHRC will only work when the virtual terminal is opened, such as executing RXVT in Gnome,kde.

A popular understanding

~/.bash_profile is interactive, login way into bash run

~/.BASHRC is an interactive non-login way into bash run

"Reason for environment variable configuration"

Under the Windows system, many software installations need to set environment variables, such as installing MySQL, if you do not set the environment variables, run the MySQL command in the non-software installation directory, will report the failure to find the file class.

So, what are environment variables? In layman's words, when specifying a directory, running the software, the relevant program will go to the directory to find the relevant files.

The most practical function of setting a variable is that you need to find some execution program or execute some shell script, do not go to the directory to execute, the path path in the system will help you to complete the search function, the popular saying is, as long as your directory in the path path, are environment variables, Execute anything and path will help you find it.

In a Linux system, if you download and install the application, it is possible to type the execution name of the "command not found" commands cannot find the prompt content, if each time in the installer directory, find the executable file, that is too irritable,

This involves setting the environment variable.

"Three ways to configure environment variables for Linux"

If you want to add a path to the $PATH There are three of the following methods

1 , Shell setting environment variables, but not in favor of this method, because a different Shell or restart Shell your settings are invalid, just

can be used temporarily

Configuration examples are as follows

$PATH = "$PATH:/New path name" (Shutdown shell, configuration disabled)

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" Computer generated alternative text: [Root@shell,] #mkdlrxx [ Root@shell Gate #echo$path/usr/11b64/qt a 3.3/bin:/usr/local/sbin:/root/bln[root@shell '] #pwd/root[root@shell,] #PATH =$ Path:/root/xx[root@shell '] #echo $PATH-/usr/1lb64/qt a 3.3/bln:/usr/local/sbin:/root/bln:/root/xx[root@shell ']#/ Usr/local/bin:/sbln:/bln:/usr/sbln:/usr/bin: Ding Fei won two Yue 11 mountains. /usr/local/bln:/sbln:/bln:/usr/sbln:/usr/binj, factory \,} spoon, ' Ba f,.~,.r~. The body of the corpse "main N added" style= "Background:url ("/e/u261/lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid # DDD; "height=" 311 "width=" 917 "/>

2 , modify / Etc/profile files, if your computer is not used in an important office environment, just to do some testing, you can

Using this method, if this method is not deprecated , because all the users in this method can use this ring

Environmental variables that can bring security issues to the system

The configuration method is as follows

Vim/etc/profile

Add in this config file

export path= "$PATH:/ the new Path ( This variable may be used by all users of this configuration method system)

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" Computer generated alternative text: and LBFBL B 72 ' Port {: one "" ; it hen plant 111 exporthistcontrol=lgnorebothexporthistcontrol=ignoredupsr. Lesf11.1.1efexportpathuserlogname do ilhostn Rob Wu histsizehistcoxtrolpath=,/root/xx "well bydefault,wewantumasktogetset. thissetsitforloglnshell#currentthresholdforsystemreserveduid/gids15200# Youcouldcheckuldgidreservationvalidltyin#/usr/share/doc/setup */uldgidfileif[a gt199] skim ["/usr/bin/,u one gn" = one/usr/ Bin/id a UN ' "];lllllask6lseumask,j"/etc/proflle "79l,1863c written to [Root@shell Gate #sour. E/etc/profile[root@shell Gate #echo$path/usr/1lb64/qt a 3.3/bin:/usr/local/sbln:/usr/local/bin:/sbln:/bln:/usr/s/root /bln:/root/xx[root@shell, # "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat Center; border:1px solid #ddd; "height=" 565 "width=" 771 "/>

3 , modify the user's ". BASHRC" file, this method is relatively secure for the user level, if you want to use the environment for a user

variables directly modify the ". BASHRC" folder in the user's home directory to

The configuration method is as follows

Vim ~/.bash_profile

Add in this file

exportpath= "$PATH"/ the new Path "

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" Computer generated alternative text: #.bash one roflle# gettheallasesandfunctionsif[one F,/.bashrc]:then,/.BASHRCFI dish Price is produced in Bu, sub #usersp Yang I.. Nvironmen:. Ndstartu. Rogr two spath=exportpath chuan into/bln bu second tun Chau tonna mouth I also stop Lintan stone from sand to a big _1 mouth door Yue Yue. Shan Mu Yue two mountain like hit Imperial ~, the household side. J Yue ... ". Yue One ~ ~ one ~. Mouth, eye door. , "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "Height = "414" width= "826"/>

the latter two methods need to be restarted West east to take effect or enter All User Variables Source/etc/profile ,

Individual users Suorce~/.bash_profile

QQ Exchange Group: 11511420

This article is from the "arrival identify" blog, be sure to keep this source http://nakedman.blog.51cto.com/7350188/1943695

Linux environment variables

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.