3.4- 系統環境變量

Linux系統使用環境變量在程序和腳本中標識自己,這爲獲取程序的系統信息提供了一種簡便的方法。
通過登錄Linux系統啓動bash shell時,bash 默認將檢查一些文件以執行命令
這些文件被稱爲啓動文件。bash處理的啓動文件依賴於bash shell的方法。可採用三種方法來啓動 bash shell

  • 在登錄時作爲默認登錄shell
  • 作爲非登錄shell的交互式shell
  • 作爲非交互式shell運行腳本

1、登錄shell
當登錄到Linux系統中,bash shell將作爲登錄shell啓動
登錄shell將查找4個不同的啓動文件來處理其中的命令。bash shell處理文件的順序如下:

  • /etc/profile
  • $HOME/.bash_profile
  • $HOME/.bash_login
  • $HOME/.profile

/etc/profile文件是bash shell在系統上的主默認啓動文件系統上的每一個用戶在登錄時都將執行此啓動文件。另外三個啓動文件特定於各個用戶
並且可以根據各用戶的需求自定義它們。

 1> /etc/profile
/etc/profile文件是 bash shell 的主默認啓動文件。當您登錄Linux系統時,bash 將執行/etc/profile啓動文件中的命令。

/etc/profile 注意點:
 1) 注意export命令行,這將確保這些環境變量對於由登錄shell生成的子進程都可用
 2) profile文件能迭代/etc/profile.d/下的所有shell文件,這使Linux系統提供了一個放置特定於應用程序的啓動文件。
/etc/profile.d的這些五年級與系統中的特定應用程序相關。
lang.csh 和 lang.sh 文件嘗試確定系統上使用的默認語言字符集,並適當設置LANG環境變量。

[root@hadoop etc]# cd /etc/profile.d
[root@hadoop profile.d]# ll
總用量 64
-rw-r--r--. 1 root root  771 10月 31 2018 256term.csh
-rw-r--r--. 1 root root  841 10月 31 2018 256term.sh
-rw-r--r--. 1 root root  196 3月  25 2017 colorgrep.csh
-rw-r--r--. 1 root root  201 3月  25 2017 colorgrep.sh
-rw-r--r--. 1 root root 1741 10月 30 2018 colorls.csh
-rw-r--r--. 1 root root 1606 10月 30 2018 colorls.sh
-rw-r--r--. 1 root root   80 10月 31 2018 csh.local
-rw-r--r--. 1 root root 1706 10月 31 2018 lang.csh
-rw-r--r--. 1 root root 2703 10月 31 2018 lang.sh
-rw-r--r--. 1 root root  123 7月  31 2015 less.csh
-rw-r--r--. 1 root root  121 7月  31 2015 less.sh
-rw-r--r--. 1 root root   81 10月 31 2018 sh.local
-rw-r--r--. 1 root root  105 10月 31 2018 vim.csh
-rw-r--r--. 1 root root  269 10月 31 2018 vim.sh
-rw-r--r--. 1 root root  164 1月  28 2014 which2.csh
-rw-r--r--. 1 root root  169 1月  28 2014 which2.sh

 2> $HOME啓動文件
$HOME/.bash_profile 和 $HOME/.bash_login 和 $HOME/.profile 三個啓動文件具備相同的功能,提供特定於用戶的啓動文件。用於定義特定於用戶的環境變量。

2、交互式shell
如果啓動了一個bash shell而沒有登錄系統,則啓動的就是一個交互式shell。
如果bash shell 作爲交互式shell啓動,則它不會出來/etc/profile文件。相反,它會檢查用戶 HOME 目錄中的.bashrc文件。

3、非交互式shell
非交互式shell是系統開始執行shell腳本用的shell。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章