Learning bash notes-Custom User Environment

Source: Internet
Author: User
1. When you and The. bash_profile,. bash_logout, And. bashrc files Exit A new shell, the. bash_profile,. bash_logout, And. bashrc files are read by bash. Every time a user logs on to the system ,. the bash_profile file is read. the bash_profile file is edited, but the file will be read again only after you log out and log in here. The new content you edited will take effect, or you can use the source command: source. /bash_profilebash allowed. two synonymous files of bash_profile: from C shell. login. bash_login and from the Bourne shell and Korn shell files. profile. profile. Only one of the three is read at login. If. bash_profile does not exist in the root directory of the user, bash searches for. bash_login. If it does not exist, it searches for. profile. (On my Ubuntu system, the root directory of the user is only the. profile file, and the content is the execution. bashrc file)
. Bash_profile is read and executed only by the logon shell. If you start a new shell by executing bash in the command line, it will read the commands in. bashrc in the view.
File. bash_logout is read and executed every time you log on to the shell and exit.
2. the alias uses alias to define the alias. For example, alias LA = 'LS-a' generally uses single quotes to include all the alias content, especially when the content contains special characters such as spaces. Use unalias to delete an alias: unalias LA to view the specific content of an alias, you can use the following command: alias la
Finally, the alias is valid only in the current bash range. If the sub-Bash is entered, the alias just defined will disappear.
3. The option shell option can change shell behavior. Its value is on or off. The options-related commands are set-O optionname and set + O optionname. You can use a set command to change multiple options by adding a-o or + O before each optionname. Here, the-symbol option to open the command, and the + symbol will close it.
Most options have an abbreviation, which can be used to replace the set-O command. For example, set-O noglob can be abbreviated as set-f.
You can type set-O to view all options and their settings.
Finally, the option is valid only in the current bash range. If the sub-Bash is entered, the option just set is invalid.

4. shoptbash 2.0 introduces the new built-in command for configuring shell behavior: shopt. This built-in command replaces the options configured by the original environment variables and the SET command.
The shopt-O function is used to copy some functions of the SET command. The command format is the option name of the shopt option. Common options are described as follows:-P displays the settings of all options without the option name; with the option name, the settings of the specified options are displayed. -S sets all options without option names, and specifies options with option names. -If U does not contain the option name, all options are unset. If option name is used, the specified option is unset.
Similarly, the options set by shopt are valid only in the current bash range. If you enter the subbash, the options just set are invalid.
5. Shell variables 5.1. you can add your own variables to the custom variables and reference shell. By convention, the built-in variable names are in uppercase. Syntax for defining variables: varname = value must have no space on both sides of the equal sign. If the value is more than one word, it must be enclosed in quotation marks. To use the variable value in a command and add the symbol $ before its name, you can use unset varname to delete the variable. All non-existent variables are assumed to be null, that is, the Null String "". [Email protected]: ~ # Words = "I am a human"
[Email protected]: ~ # Echo $ words
I am a human
[Email protected]: ~ # Unset words
[Email protected]: ~ # Echo $ words

[Email protected]: ~ #

. The built-in variables are some common bash built-in variables. You can use the echo $ variable name to view them.

Ppid: The process ID of the user executing the current bash.

PWD: current working directory (print working directory.
Oldpwd: the last working directory. You can use CD to switch between the last two directories.
Reply: When the READ command does not have a parameter, it is directly set to reply.
UID: User ID used to log on to the system
EUID: ID of the current user

Bash: the complete path of bash.

Bash_version: Bash version.
Shlvl: Number of bash layers. Each time a bash command is executed, 1 is automatically added.
Random: generates a random number without a seed.
Seconds: the number of seconds from the beginning to the current running of the Current Shell
Optarg: the last option parameter for getopts Processing
Optind: The next parameter number to be processed by getopts
Hosttype: Machine Type

Machtype: Machine Type

Ostype: name of the job system.
Ifs: Default delimiter
Path: The Path automatically searched by the command, which is similar to the Windows environment variable.
Home: the "home" directory of the current user. You can use ~ Replace
Cdpath: Search Path of the CD command

Lineno: displays the number of commands that have just been executed. The command executed after logon starts from 1, and 1 is automatically added for every execution.
Histcmd: the number of historical commands currently logged, equivalent to history | WC-l
Env: If this parameter is set, every time a shell script is executed, the file name set by this parameter will be executed as the Environment setting.
Mail: If this parameter is set and mailpath is not set, Bash will notify the user when a letter comes in.
Mailcheck: set the time to check an email.
Mailpath: a string of email check paths
Mail_warning: If the email is read, a message is displayed.
PS1: A level-1 prompt is a variable that sets the content before the command prompt ($ for common users and # for root users ).
PS2: second-level prompt. Set the prompt after wrapping or executing the do command. The default value is>
PS3: prompt message used by the SELECT command.
PS4: When you use set-X or bash-X to execute the script, the prompt that tracks the detailed running process of the script. The default value is +
Histsize: Number of historical commands recorded
Histfile: The file that records historical commands. The default value is ~ /. Bash_history
Histfilesize: maximum value of the History command file
Opterr: if it is set to 1, Bash will display the getopts error.
Prompt_command: the value of this variable is one or a group of commands. If it is set, run the command here before each command is executed.
Ignoreeof: Use the EOF value as the input and set it to 10.
Tmout: time-out period. If you have not executed any command within the time specified by this variable, logout is automatically triggered.
Fcedit: Default FC Editor

6. environment variables by default, only one type of food is known to all sub-processes, that is, a specific type of shell variable called environment variables. The built-in variables described above are actually environment variables such as home, mail, and path.
Any variable can be changed to an environment variable. First, it must be defined as usual, and then it must be exported using the following command: Export varname can also be used to assign values to and export variables into a statement: export myname = Alice can also define a variable as a variable in a specific sub-process by adding a variable value before the command, such as: varname = value command

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.