Linux environment variable operations

Source: Internet
Author: User
Linux environment variable operations-general Linux technology-Linux programming and kernel information. The following is a detailed description. The main environment variables include the PATH system PATH, the HOME system root directory, and the number of records that History commands are stored in HISTSIZE. LOGNAME: HOSTNAME: The Host Name of the current user logon. SHELL: The SHELL name used by the current host, LANG/LANGUAGE environment variable, MAIL directory

Command: echo $ PATH

Export welcome = "hh :"

Env show all, env | grep welcome found

Set displays all locally defined

Unset $ welcome Delete Environment Variables

Readonly $ welcome cannot be modified or deleted.

You can use C to access environment variables: several functions are used:

Getenv () is used to access an environment variable. The input parameter is the name of the variable to be accessed, and the return value is a string. If the accessed environment variable does not exist, NULL is returned.

Setenv () is a function used to set an environment variable in a program.

Unsetenv () is a function used to clear a specific environment variable.

In addition, the pointer variable environ points to a list containing all environment variables. The following program can print all the environment variables in the current running environment:

# I nclude
Extern char ** environ;
Int main ()
{
Char ** var;
For (var = environ; * var! = NULL; ++ var)
Printf ("% s \ n", * var );
Return 0;
}
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.