Bash Shell User Environment

Source: Internet
Author: User
Tags posix

  • Introduced

    Understand The boot sequence of Linux also helps to understand this content, loading the user environment is the last step of Linux boot. Different shells use different configuration files : Bash (. Profile), Ksh (. Profiles), CSH (. Login).

    The Bash Shell is designed to be compatible with SH, ksh, which is checked in the user's home directory in turn . Bash_profile,. Bash_login,. profile exists and loads the first file found. Regardless of the name of the file, the same principle of loading the user environment, only one configuration file can be set. However, if there is a need for compatible Bash,ksh , configure only. Profile .   If the Bash profile is modified after the user has logged in , the user can manually load the file to take effect, such as .  /etc/profile. ~/.bash_profile

    /etc/skelthe directory has.Bash_ Profile  .BASHRC ,When a new user is created, /etc/Skelall files in the file are copied and placed in the user's home directory to set the user's environment.



  • Concept

    Shell Environment script: Management The best scenario for a bash environment is through /etc/profile.d/*.sh, where the *.sh file in /etc/profile.d/ is the profile used to store the application software , the environment variables used to configure the appropriate software. Instead of modifying/etc/profile directly .


    Child Shell: Why let a script or command run in a child shell? Because starting a child shell creates a completely new, independent execution environment, the changes that occur in the child shell do not affect the parent shell environment .

    load file: and programmatically using include same principle, Inserts the specified file into the current file at the defined location. bash Shell allow users to centralize multiple commands in a single file, and then execute them as if they were typed directly at the prompt, a process known as loading a file. The command to load the file executes in the current shell shell environment, the command to get the file is shell built-in command source (. is the source )

    Shell launched in bash--login, Log on to a machine to see the first shell, log in to the Virtual Console, Telnet, start X shell shell that is activated when the user logs on, /etc/passwd

    Non-logon shell: in Bash- initiated Shell is a non- login shell except the login shell, such as a new terminal opened under X graphics , a sub-shell, a parenthesis command grouping, execution Shell script when creating a new non-logon shell. Shell Programs that are executed manually after the user logs on


    Interactive Shell: manually initiated sub- Shell, newly opened X terminal, etc.

    non-interactive shell: start scripts as shell scripts, command replacements, Shell calls, etc. to avoid potential startup script side effects, non-interactive shell does not load startup script at startup




650) this.width=650; "src=" Http://img1.51cto.com/attachment/201411/2/2363901_14149182549tqX.png "/>



  • Loading of the environment when using the shell in different ways


    Interactive login Shell

    login is divided into local login and remote login,bash reads environment settings from four files when user logs in:

    The login shell loads first/etc/profile(Global settings, this file can also be obtained in the execution of other files) , then, in the user's home directory, press.Bash_ Profile .Bash_Login  . Profilepriority execution of one of the files ,LoginShellwhen logout,If the home directory has. Bash _ Logout , then execute .

    Load Order:

    /etc/profile >/etc/profile.d/*.sh>~/.bash_profile (. bash_login,. Profile) > ~/.BASHRC >/etc/bashrc< /c11>



Global Settings file:

①/etc/profile

② /ETC/BASHRC

Current User settings file:

③ ~/.bash_profile profile for standalone users

④~/.bashrc # If you make the alias command permanent, you can write the alias configuration to this file, and when the user logs in to the shell, execute the command (the user used to customize the shell)

Interactive non-login shell ( execute new shell)

. BASHRC The environment variable setting for user login is separated from the environment variable setting of the child shell and has a separate execution environment.

Loading ~/.BASHRC, This file is loaded by default only /ETC/BASHRC, ~/.bashrc>/etc/bashrc>/etc/profile.d/*.sh

non-interactive non-logon Shell

Check the variable bash_env first, and if it is defined, execute the contents of the startup file it defines before executing the script. No boot text is loaded by default

Call Bash with SH file name

Emulate the old version of SH and try to be compatible with the POSIX standard (bash-specific functionality will be lost)

Loginshell calling/bin/sh,bash reads/etc/profile and ~/.profile

Interactive Shell: Executes/bin/sh, fork a child shell, and examine and execute the contents defined in the ENV variable.

Execute shell script: The first behavior in #!/bin/sh, bash does not execute any configuration files.

Execute in Bash--posix mode

Bash use the POSIX standard compatibility feature to check and execute the content defined in the env variable.

Execute bash-r or call with Rbash name

Restricted mode, the Bash feature is limited to allow users to have a few features for security reasons. This mode executes ~/.bash RC

Related documents

/etc/profile : All user login will execute, set the variable ( global ) can be used in All Users , by Root Unified Maintenance

/ETC/BASHRC : for all interactive Shell

/etc/skel: The directory contains initialization files for all users

Some of the files that users can customize:

~/.bash_ Profile: current user environment configuration. , login file run bash

~/.BASHRC : shell Span style= "Color:rgb (0,0,0); font-family: ' New song body ';" > environment The file is read and is interactive non login bash

~/.bash_logout When a user logs on, only the clear command is executed by default

This article is from the "Adelphos" blog, make sure to keep this source http://adelphos.blog.51cto.com/2363901/1570938

Bash Shell User Environment

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.