Verbatim https://www.dazhuanlan.com/2019/08/26/5d62f93a80696/
bash environment configuration
Work environment under Mac environment, the default Mac under bash is not .bashrc
, leading some automated tools are not properly
configure their own environment variables, and finally problems.
These configuration files of bash role
-
.bash_profile
From the literal meaning
profile
associated with the account, it is read each time a user login system, all commands will be executed inside the bash.
In other shell inside presence.profile
and.login
these they are and.bash_profile
the role is the same. -
.bashrc
From the literal meaning
rc
associated with configuration items, each bash started (the process of) time, will read the document. In general there will call in .bash_profile.bashrc
script to configure a unified user environment. -
.bash_logout
Better understanding, read on exit shell. So we can put some commands to clean up our work on this document.
As well as some system-level configuration items, /etc/bashrc
and /etc/profile
, when found in the user's home directory .bash_profile
, and .bashrc
when, will read the two documents, in centos, .bashrc
will call /etc/bashrc
. In addition .bash_history
is the history of a document for the bash shell
Two interactive shell property
One of whether interactive shell
(Interactive Shell), the other, whether login shell
(Login Shell)
-
Interactive Shell: no non-option argument, no -c, coupled with the standard input and standard output terminal or Bash instance starts with -i parameter. $ Can set or by detecting whether PS1 variable - the return value to determine whether to include subtitles i. What is no non-option argument? Bash Shell script examples such as bash ~ / myscript / clear_temp_files.sh this execution, it is not interactive Shell, because the script's path is non-option argument. -c is doing? Is to use a string as a parameter passed Bash, such as bash -c 'ls -ahl', this process is not considered interactive Shell Shell.
The interactive non-login Shell document is loaded in the following order:
12/etc/bashrc~/.bashrc -
Login Shell: The first argument to 0 - Bash instance at the beginning of the number, or start with -login parameters Bash Shell. More weird, what is the first parameter to 0 - the beginning of the number? You need only log on a * nix system, Mac will do, Linux can do, and then echo $ 0, you will understand, it surprised, it turned out to be a value -bash. Really it is - the beginning of the number! !
Login Shell (whether or not interactive) document loaded in the following order:
1234/etc/profile~/.bash_profile~/.bash_login~/.profile
A crontab script, if not treated, neither interactive Shell, nor are logged Shell, so all configuration is not enforced.
How to deal with? For example, you can change it to shabang #!/bin/bash -l
let Shell login script to explain the execution, you can load /etc/profile
or invoke Bash interpreter, plus -l
parameters can also be.
The above information also explains why there is no execution at Mac .bashrc
reason, because it is interactive shell
shell commands to set the set and shopt
set command can be used to customize the shell environment, use the option "o" to open or close the options. Such as opening options: set -o
Option to close the selection of projects: set +o
options.
Built-in set command options
Option name | Quick switch | meaning |
---|---|---|
allexport | -a | This option is set to start automatically marked a new variable to be output or modified variables, until it is reset |
braceexpand | -B | Open the brace expansion, which is a default setting |
emacs | Use the built-in editor emacs command line editing, is a default setting | |
erreximus | -e | When the exit command returns a non-zero exit status (failure) when. When reading the document does not set initialization |
histexpand | -H | Open the execution history substitution! And! Extended, is a default setting |
history | Open a command line history, on by default | |
ignoreeof | Prohibit exit the shell with EOF (Ctrl + D) key. You must type exit to exit. Equivalent to setting shell variables IGNOREEOF = 10 | |
keyword | -k | The keyword arguments into the command environment |
interactive-comments | For interactive shell, the back of the annotations as text character # | |
monitor | -m | Setting job control |
noclobber | -C | Prevent document is rewritten when redirecting |
noexec | -n | Read commands but do not execute. Used to check the script syntax. Do not open the run-time interactive |
noglob | -d | Prohibit extension with the path name. That is close wildcard |
notify | -b | Notify the user when the job is complete background |
nounset | -u | It displays an error message when a variable is not set extension |
onecmd | -t | After reading and executing the command quit |
physical | -P | When setting, type cd or pwd prohibited symbolic links. Instead of using physical directory |
privileged | -p | After setting, shell .profile or ENV not read the document, and does not inherit shell functions from the environment, will automatically open the script setuid privileges |
verbose | -v | Turn on verbose debug mode |
we | Use the built-in editor vi command line editing | |
xtrace | -x | 为调试打开echo模式 |
shopt
命令是set
命令的一种替代,很多方面都和set
命令一样,但它增加了很多选项。可有使用-p
选项来查看shopt
选项的设置。-u
开关表示一个复位的选项,-s
表示选项当前被设置。
|
|
shopt命令选项
选项 | 含义 |
---|---|
cdable_vars | 如果给cd内置命令的参数不是一个目录,就假设它是一个变量名,变量的值是将要转换到的目录 |
cdspell | 纠正cd命令中目录名的较小拼写错误。检查的错误包括颠倒顺序的字符,遗漏的字符以及重复的字符。如果知道一处修改,正确的路径就打印出,命令将继续。只用于交互式shell |
checkhash | bash在试图执行一个命令前,先在哈希表中寻找,以确定命令是否存在。如果命令不存在,就执行正常路径搜索 |
checkwinsize | bash在每个命令后检查窗口大小,如果有必要,就更新LINES和COLUMNS的值 |
cmdhist | bash试图将一个多行命令的所有行保存在同一个历史项中。这使得多行命令的重新编辑更方便 |
dotglob | bash在文档名扩展的结果中包括以点(.)开头的文档名 |
execfail | 如果一个交互式shell不能执行指定给exec内置命令作为参数的文档,它不会退出。如果exec失败,一个交互式shell不会退出 |
expand_aliases | 别名被扩展。默认为打开 |
extglob | 打开扩展的模式匹配特征(正常的表达式元字符来自Korn shell的文档名扩展) |
histappend | When the shell exits, history list will be added to the value of the variable HISTFILE named in the document, rather than overwriting the document |
histreedit | If readline is being used, users have the opportunity to re-edit a failed history substitution |
histverify | If set, and readline is being used, the results of history substitution are not immediately passed to the shell parser. The results are loaded into row but readline editing buffer, allowing further modified |
host complete | If set, and readine being used when completing a word containing @ bash will attempt to perform hostname completions. The default is Open |
huponexit | If set, when an interactive login shell exits, bash sends a SIGHUP (hangup signal) to all jobs |
interactive_comments | In an interactive shell, it is ignored to allow the word beginning with # and other characters on the same line. The default is Open |
lithist | If you open and cmdhist option is also open, multi-line commands are saved to the history with embedded newline, without the need to separate where possible with a semicolon |
mailwarn | If set, bash to check e-mail and documents since the last inspection has been accessed, the message "The mail in mailfile has been read" |
nocaseglob | If set, when performing document name extension, bash match the document name in a case-insensitive way |
nullglob | If set, bash allows the document did not match any document name extension mode to an empty string, rather than themselves |
promptvars | If set, prompt strings undergo variable and parameter expansion after being extended. The default is Open |
restricted_shell | If the shell is started in restricted mode to set this option. This value can not be changed. When performing a startup document, you can not reset the option, allowed to start to find out whether the document is limited shell |
sourcepath | If set, source built-in command uses the value of PATH to find the directory that contains the document as an argument. The default is Open |
source | Dot (.) Synonyms |
shift_verbose | If this option is set, when the count exceeds the number of parameters of the mobile position, shift builtin prints an error message |