Environment variables in Linux

Source: Internet
Author: User

Explain:
The main storage is data related to the operating environment of the system.
Range:
Code settings: The current shell and all child shells of the current shell are in effect
Config file: Effective in all shells
Grammar:
Declaration variables:
Export variable name = variable Value
View all variables:
Env
To delete a variable:
unset variable Name
Important variables:
PATH:
A. Path to the system Lookup command
B. Write your own executable file if placed in a folder under the path, you can directly execute
C. In fact, the command complement of Linux is also in the directory of path to find the command
D. Extending the PATH range (temporary change): Path= "$PATH":/root/xiaol/sh

Example:
Custom variable Name
[Email protected] ~]# Name=xiaol
Environment variable Age
[Email protected] ~]# export age=18

To promote a custom variable sex to an environment variable
[Email protected] ~]# Sex=man
[[email protected] ~]# export sex

Use set to view all variables, including the custom and environment
[[Email protected] ~]# Set | grep name; Set | grep age; Set | grep sex
Name=xiaol
Age=18
Sex=man

Use env to view environment variables
[Email protected] ~]# env | grep name; env | grep age; env | grep sex
Age=18
Sex=man

Turn on the child shell
[Email protected] ~]# bash

View current shell status
[Email protected] ~]# Pstree
INIT─┬─AUDITD───{AUDITD}
├─crond
├─dhclient
├─login───bash
├─master─┬─pickup
│└─qmgr
├─5*[mingetty]
├─RSYSLOGD───3*[{RSYSLOGD}]
├─smbd───smbd
├─sshd───sshd───bash───bash───pstree
└─UDEVD───2*[UDEVD]

Use set to view all variables, including the custom and environment
[[Email protected] ~]# Set | grep name; Set | grep age; Set | grep sex
Age=18
Sex=man

Use env to view environment variables
[Email protected] ~]# env | grep name; env | grep age; env | grep sex
Age=18
Sex=man

Exit Child shell
[Email protected]t ~]# exit

View current shell status
[Email protected] ~]# Pstree
INIT─┬─AUDITD───{AUDITD}
├─crond
├─dhclient
├─login───bash
├─master─┬─pickup
│└─qmgr
├─5*[mingetty]
├─RSYSLOGD───3*[{RSYSLOGD}]
├─smbd───smbd
├─sshd───sshd───bash───pstree
└─UDEVD───2*[UDEVD]

Delete environment variable age
[Email protected] ~]# unset age

Use env to view environment variables
[Email protected] ~]# env | grep name; env | grep age; env | grep sex
Sex=man
[Email protected] ~]#

Environment variables in 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.