Linux system environment variables. BASH_PROFILE/BASHRC file

Source: Internet
Author: User

View of system environment variables:

[[Email protected] ~]# env
Hostname=localhost.localdomain
Selinux_role_requested=
Term=xterm
Shell=/bin/bash
histsize=1000
ssh_client=192.168.7.105 50641 22
Selinux_use_current_range=
qtdir=/usr/lib/qt-3.3
Qtinc=/usr/lib/qt-3.3/includ

========= Many

Where the mailer of path is declared as:
Path= $PATH: <path 1>:<path 2>:<path 3>:------: <path n>

When a program in a directory is running, you can search for the relevant commands in the directory that corresponds to the path defined in the file, so you can use the commands in the compiler. So the value of path is a series of directories, and when you run a program, Linux searches under these directories for the command to set the value of path.

Direct with export command

Add the/data/test/hellow.sh script in path to enable the script to execute in a different directory.

[Email protected]/]# cd/data/test
[email protected] test]# LL
Total Dosage 4
-rwx------1 root root 32 October 13:02 hellow.sh
[[email protected] test]# echo $PATH #显示 $PATH variable
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/x11r6/ Bin:/root/bin
[[Email protected] test]# CD/
[[email protected]/]# Export path=/data/test: Add script path $PATH #在 $PATH
[Email protected]/]# export|grep test #查看 $PATH
Declare-x oldpwd= "/data/test"
Declare-x path= "/data/test:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/ Sbin:/usr/bin:/usr/x11r6/bin:/root/bin "

Modify Profile File

[Email protected]/]# Vi/etc/profile

Export PATH USER LOGNAME MAIL HOSTNAME histsize INPUTRC #加入

Root/.bash_profile is one of the Linux three environment variable settings files, and the scope of this environment variable is only the current user

Modify the. bashrc file

[Email protected]/]# VI/ROOT/.BASHRC
#. BASHRC

# User specific aliases and functions

Alias Rm=rm-i
Alias Cp=cp-i
Alias Mv=mv-i

# Source Global Definitions
if [-F/ETC/BASHRC]; Then
. /etc/bashrc
Fi

Export path= "$PATH:/data/test/"

Modify the environment variable by modifying the environment variable definition file.

It is important to note that, in general, this is only applicable to ordinary users and avoids modifying the root user's environment definition file, as that may pose a potential hazard.

--------------------------------------------------------------------------------

$CD #到用户根目录下

$ls-A # View all files, including hidden files

$vi. Bash_profile # Modify the environment variable definition file

--------------------------------------------------------------------------------

Then 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

Related Article

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.