/etc/skel/.bash_profile

/etc/skel/.bash_profile

我想將程式碼放入一個檔案中,當建立新會話時,Debian 系統上的所有使用者都會呼叫該檔案。

/etc/profile僅受登入會話影響。

答案1

所有使用者為新的 bash 會話調用的文件

當您閱讀以下章節時祈求在手冊中你會知道沒有這樣的文件。https://linux.die.net/man/1/bash

我手邊沒有 Debian 盒子,但 Debian 可能會做一些與 RHEL/CentOS 類似的事情:預設情況下,這些發行版從/etc/skell a~/.bash_profile和 a部署~/.bashrc到用戶主目錄。

當 bash 作為互動式登入 shell 被呼叫時,~/.bash_profile應該載入它。

/etc/skel/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

當啟動非登入 shell 的互動式 shell 時,bash 會讀取並執行以下命令~/.bashrc

透過加載,~/.bashrc~/.bash_profile將獲得一個將為正常會話和登入會話加載的檔案。

/etc/skel/.bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# User specific aliases and functions  

反過來~/.bashrc將載入全域文件/etc/bashrc,您將獲得一個系統範圍的文件,該文件會為登入和非登入互動式 bash 會話載入。

相關內容