Bash Environment configuration:
configuration file, the scope of effective, there are two categories:
Global configuration:
/etc/profile,/etc/profile.d/*.sh,/ETC/BASHRC
Personal configuration:
~/.bash_profile, ~/.BASHRC
By function, there are two categories:
Profile class: Provides configuration for the interactive logon shell
/etc/profile,/etc/profile.d/*.sh
~/.bash_profile
Function:
(1) Define environment variables, such as path, PS1
(2) run a command or script
BASHRC class: Provides configuration for non-interactive logon shell
/etc/bashrc
~/.bashrc
Function:
(1) Define command aliases;
(2) define local variables;
Variables: Memory space, variable name
Type:
Environment variables: scope current shell process and its child processes
Local variable: scope current shell process
Local variables: scoped only to a snippet of code in the current shell process (usually a function context)
Position variable: $ $, $
Special variables: $? ( The return result of the previous command, normal is 0, the other is wrong )
How variables are defined:
Bash built-in variables: can be called directly, built in a number of environment variables, such as Path
Custom variables:
Variable assignment: variable name = value
Bash Weak type:
When a variable stores data, it is written by default, and any variable can be directly referenced without being declared;
120 (character type): 3byte
120 (numeric type): 1byte
Note: This is also the case in PHP.
To define a local variable:
Name=value
View: Set
Define Environment variables:
Export Name=value
Declare-x Name=value
View: env, printenv, export
Undo Variable:
unset name
Reference variable:
${name}, $name
Reference symbols in bash:
': Strong reference, variable substitution does not occur
"": Weak reference
": Command Reference
Shell Logon Type:
Interactive login:
Login directly through the terminal;
User Switching implemented by su-l username command;
Non-interactive logon:
A command-line window opens under the graphical interface;
Execute the script;
Su Username;
Configuration file Action Order:
Interactive login:
/etc/profile--/etc/profile.d/*.sh--and ~/.bash_profile--~/.BASHRC--/ETC/BASHRC
Non-interactive logon:
~/.BASHRC--/ETC/BASHRC-/etc/profile.d/*.sh
How does the new configuration of the Edit profile definition take effect?
(1) Re-login;
(2) Let the current shell process to re-read the specified configuration file;
Source/path/to/somefile
. /path/to/somefile
Note: It is possible to cause side effects
actual combat:
1. Define aliases that are valid for all uses?
Answer: just VIM/ETC/BASHRC
2. What if only the modification of the PATH environment variable takes effect for the root user?
Answer:vim ~/.BASHRC can modify the path variable
This article is from the "Wind Rhyme" blog, please be sure to keep this source http://chinalx1.blog.51cto.com/2334265/1691665
Linux Bash Basics