標籤:系統和使用者的環境變數設定檔
用來規定環境變數的設定檔 /etc/profile,它表示系統相關的環境變數
注:不過要想改變某些環境變數的話,最好在/etc/profile.d/下面去定義,寫自己的shell 。
最好不要更改/etc/profile檔案。
比如定義個path.sh
[[email protected] ~]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/tmp/:/data/bin/ #自己新定義的PATH
重設並生效
[[email protected] ~]# source /etc/profile
[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/:/data/bin/
另外一個設定檔/etc/bashrc,會定義PS1,umask(/etc/profile檔案裡也有定義)
注:這個檔案最好也不要修改;最好在/etc/profile.d/下面去定義,寫自己的shell
查看PS1
[[email protected] ~]# echo $PS1 #PS1定義的我們命令的首碼
[\[email protected]\h \W]\$
修改PS1,把W換成w,區別就是w會顯示絕對路徑,而W會顯示路徑的最後一段
[[email protected] ~]# PS1=‘[\[email protected]\h \w]\$ ‘
[[email protected] ~]# cd /etc/init.d/
[[email protected] /etc/init.d]#
[[email protected] /etc/init.d]# PS1=‘[\[email protected]\h \W]\$ ‘
[[email protected] init.d]# cd /etc/init.d/
[[email protected] init.d]#
還可以加上時間\t
[[email protected] init.d]# PS1=‘[\[email protected]\h\t \W]\$ ‘
[[email protected]19:29:31 init.d]#
root使用者是# 普通使用者是$
[[email protected] ~]# su - wyy
[[email protected] ~]$
/etc/profile、/etc/bashrc是關於系統層級的。除了這兩個之外,還有一些在使用者的家目錄下,可以用 ls -la .
可以看到有幾個以.bash開頭的。 .bash_profile檔案和我們系統的/etc/profile檔案是一類檔案,很像。/etc/profile
作一個全域的,任何使用者都能用到的這樣的一個設定檔;若想針對使用者自己來定義一些環境變數,可以在這個
.bash_profile裡去定義。
.bashrc這個裡面會定義使用者的別名,當使用者登入時以及每次開啟新的shell時執行該檔案。
注: .bashrc會被.bash_profile調用
如果在.bashrc裡面定義了變數,然後又在.bash_profile裡面unset該變數,那麼當我們登入一個終端時,echo該變數的值為空白
本文出自 “linux” 部落格,轉載請與作者聯絡!
系統和使用者的環境變數設定檔