Article Title: Summary of Linux environment variable settings. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. Introduction
In linux, If you download and install an application, it is very likely that the prompt "command not found" appears when you type its name. If you find the executable file in the installation target folder every time, it is too cumbersome to find the executable file. This involves setting the environment variable PATH, and the PATH setting is also an integral part of customized environment variables in linux. Based on RedHat 9.0, this article describes how to customize environment variables in detail.
2. Introduction to variables
Linux is a multi-user operating system. Each user logs on to the system and has a dedicated runtime environment. Generally, the default environment of each user is the same. The default environment is actually the definition of a set of environment variables. You can customize your running environment by modifying the corresponding system environment variables.
3. Common Environment Variables
$ PATH: determines the directories to which shell will look for commands or programs.
$ HOME: HOME Directory of the current user
$ MAIL: the MAIL storage directory of the current user.
$ SHELL: The Shell used by the current user.
$ HISTSIZE: the number of records that save historical commands.
$ LOGNAME: The Login Name of the current user.
$ HOSTNAME: indicates the host name. Many applications usually obtain the host name from this environment variable if they want to use the host name.
$ LANG/LANGUGE: it is a language-related environment variable that can be modified by users in multiple languages.
$ PS1: A Basic prompt. For root users, it is #. For common users, it is $. You can also use more complex values.
$ PS2: A subsidiary prompt. The default value is "> ". You can modify this environment variable to modify the current command line. For example, the following command will change the prompt to the string "Hello, My NewPrompt :)".
# PS1 = "Hello, My NewPrompt :)"
$ IFS: the input domain separator. When the shell reads the input, it is used to separate a group of characters of words, which are usually spaces, tabs, and line breaks.
$0: name of the shell script.
For example, in my Linux system:
$ Echo $0
/Bin/bash
$ #: Number of parameters passed to the script.
$: Process ID of the shell script. The script usually uses it to generate a unique temporary file, such as/tmp/tmfile _ $
For example, in my Linux system:
$ Echo $
31038 # indicates that the current shell process is 31038
4. export command
The export command imports the variable as its parameter to the sub-shell and makes it valid in the sub-shell. The export command creates a parameter as an environment variable, which can be seen by other scripts and programs called by the current program.
4.1 Export experiment Variables
(1) Let's first list the script program export2
#! /Bin/sh
Echo "$ foo"
Echo "$ bar"
(2) then the script export1. At the end of this script, we call export2:
#! /Bin/sh
Foo = "The first meta-syntactic variable"
Export bar = "The second meta-syntactic variable"
Export2
Run this script to get the following output:
$ Export1
# This is a space, because the variable foo is not available in export2, so $ foo is copied as null
The second meta-syntactic variable
$
4.2 set a new environment variable WELCOME
$ Export WELCOME = "Hello! "
$ Echo $ WELCOME
Hello!
[1] [2] Next page