linux bash文件,linux之bash配置文件
為何我們登錄linux后默認有很多環境變量?
首先我們登錄bash有兩種方式:login shell和non-login shell;
login shell:取得bash需要完整的登錄流程,即/etc/profile(系統整體的設定)和~.bash_profile ~.bash_login ~/.profile(個人設定);
non-login shell:會讀取這個~/.bashrc配置文件
以下4點會取得login shell:
登錄系統時獲得的頂層shell,無論是通過本地終端登錄,還是通過網絡ssh登錄。這種情況下獲得的login shell是一個交互式shell。
在終端下使用--login選項調用bash,可以獲得一個交互式login shell。
在腳本中使用--login選項調用bash(比如在shell腳本第一行做如下指定:#!/bin/bash --login),此時得到一個非交互式的login shell。
使用"su -"切換到指定用戶時,獲得此用戶的login shell。如果不使用"-",則獲得non-login shell。
1. /etc/profile:若想所有用戶登錄系統時都要改變,就修改此文件,建議不修改。[root@www?~]#?cat?-n?/etc/profile?#共有80多行
1??#?/etc/profile
2
3??#?System?wide?environment?and?startup?programs,?for?login?setup
4??#?Functions?and?aliases?go?in?/etc/bashrc
5
6??#?It's?NOT?a?good?idea?to?change?this?file?unless?you?know?what?you
7??#?are?doing.?It's?much?better?to?create?a?custom.sh?shell?script?in
8??#?/etc/profile.d/?to?make?custom?changes?to?your?environment,?as?this
9??#?will?prevent?the?need?for?merging?in?future?updates.
…………
根據用戶設定PATH變量
…………
有PATH?USER?LOGNAME?MAIL?HOSTNAME?HISTSIZE?HISTCONTROL這些環境變量等信息;
此文件還會調用/etc/profile.d/*.sh,如for?i?in?/etc/profile.d/*.sh?;?do
if?[?-r?"$i"?];?then
if?[?"${-#*i}"?!=?"$-"?];?then
.?"$i"
else
.?"$i"?>/dev/null?2>&1
fi
fi
done
[root@www?~]#?ls?-l?/etc/profile.d/
總用量?44
-rw-r--r--.?1?root?root?1127?10月?17?2013?colorls.csh
-rw-r--r--.?1?root?root?1143?10月?17?2013?colorls.sh
-rw-r--r--.?1?root?root??192?8月??27?2013?glib2.csh
-rw-r--r--.?1?root?root??192?8月??27?2013?glib2.sh
-rw-r--r--.?1?root?root?1741?11月?23?2013?lang.csh
-rw-r--r--.?1?root?root?2706?11月?23?2013?lang.sh
-rw-r--r--.?1?root?root??122?2月???7?2007?less.csh
-rw-r--r--.?1?root?root??108?2月???7?2007?less.sh
-rw-r--r--.?1?root?root??105?12月?22?2016?vim.csh
-rw-r--r--.?1?root?root??269?12月?22?2016?vim.sh
-rw-r--r--.?1?root?root??169?5月??20?2009?which2.sh由lang.sh又去調用/etc/sysconfig/i18n來設置語系。
2.? 讀完/etc/profile后調用完其他文件。就是調用~/.bash_profile ~/.bash_login ~/.profile
只會讀取上面三個文件中的其中一個,默認順序就是以上順序,
當修改了整體配置文件或個人配置文件,需要使用source命令來讀取這些文件來生效?;蛘呤褂? 配置文件使配置文件生效
總結
以上是生活随笔為你收集整理的linux bash文件,linux之bash配置文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在Linux系统下生产者消费者,生产者-
- 下一篇: linux 文件夹隐藏属性,Linux基