在用戶登錄的時候執行sh腳本的順序:每次登錄的時候都會完全執行的
/etc/profile.d/file
/etc/profile
/etc/bashrc
/root/.bashrc
/root/.bash_profile
所以如果你想覆蓋的話你也就知道了怎么去覆蓋
如果想弄明白以上的問題,嘗試着去讀man bash這是最直觀的說明了。
名詞理解:
- login shell:例如tty1-tty6登陸時候要輸入用戶名密碼,就是login shell,
解析如下文件
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile - non login shell:
- interactive shell: 交互式
- non-interactively:非交互式
A login shell is one whose first character of argument zero is a -, or one started with the –login option.
交互式login shell的情況如下:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The –noprofile option may be used when the shell is started to inhibit this behavior.(使用–noprofile選項激活Bash可以禁止其讀任何初始化文件)
When a login shell exits, bash reads and executes commands from the files ~/.bash_logout and /etc/bash.bash_logout, if the files exists.
交互式 non login shell情況如下:
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the –norc option. The –rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
非交互式
當運行shell腳本時,bash是非交互式的
在interactive shell下執行腳本,將會啟動non-interactive shell, non-interactive shell從其父進程處繼承環境變量
環境變量用戶變量永久變量臨時變量(這些概念這的很亂)
env
export
set
unset
如果能夠搞清楚這些東西,也就清楚了linux的變量是從哪里來的了,也就明白了,shell變量不過如此,而且也明白了shell變量和linux內核真的是相距甚遠。我們最容易犯的錯誤就是所見即所得,我們總是以為bash是linux,其實不然,bash只是一層殼,而真正的linux內核的各種資源分配,線程調度才是linux內核。
問題:當我們輸入一個命令時,linux是怎么去解析的?
我想會去搜索這個命令並執行這個命令。