tag:blogger.com,1999:blog-3261601569262268959.post9109229049113806908..comments2023-11-28T15:52:46.948+08:00Comments on 阿舍的隨手記記、隨手寫寫...: Ubuntu 讀取 .bashrc 和 .bash_profile 檔案的時機Unknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-3261601569262268959.post-30047347271138566612015-04-18T16:54:32.022+08:002015-04-18T16:54:32.022+08:00Hello,
瞭解。 謝謝囉 ! ... ^^=Hello,<br /><br />瞭解。 謝謝囉 ! ... ^^=Arthurhttps://www.blogger.com/profile/07808606363556069115noreply@blogger.comtag:blogger.com,1999:blog-3261601569262268959.post-12488572602281342042015-04-17T18:45:25.770+08:002015-04-17T18:45:25.770+08:00所以有一種方式, 可以把「.bash_profile」拿掉。
然後自己寫的script,寫在另一個檔...所以有一種方式, 可以把「.bash_profile」拿掉。<br />然後自己寫的script,寫在另一個檔,另外命名,不要叫「.bash_profile」。<br />然後在「.bashrc」去執行。<br /><br />另外你也可以仿造「/etc/profile」,<br />裡面「if [ -d /etc/profile.d ]; then」哪一段,<br />寫在「~/.bashrc」裡。<br />就會自動執行某個資料夾裡的script檔案。<br /><br /><br />以上參考鵝從未在裏面https://www.blogger.com/profile/05998704176013859038noreply@blogger.comtag:blogger.com,1999:blog-3261601569262268959.post-18484925069909117582015-04-17T18:45:17.104+08:002015-04-17T18:45:17.104+08:00而你的方式,因為「~/.bash_profile」存在。
* 「登入的時候」,執行「~/.bash...而你的方式,因為「~/.bash_profile」存在。<br /><br />* 「登入的時候」,執行「~/.bash_profile」,然後你在「~/.bash_profile」,再加入執行「. ~/.bashrc」。<br /><br />* 在「X Window 開 Terminal」的時候,執行「.bashrc」。<br /><br /><br />所以你的方式,其實是一樣的。<br />只不過「~/.profile」換成「~/.bash_profile」。<br /><br /><br />附註: 可以在這些script,加入「echo」訊息,測試的時候,就可以看到執行順序了。 鵝從未在裏面https://www.blogger.com/profile/05998704176013859038noreply@blogger.comtag:blogger.com,1999:blog-3261601569262268959.post-39099558167820881342015-04-17T18:45:06.468+08:002015-04-17T18:45:06.468+08:00我要表達的是
```
我測試的結果,若「~/.bash_profile」不存在,就都會執行「.ba...我要表達的是<br /><br />```<br />我測試的結果,若「~/.bash_profile」不存在,就都會執行「.bashrc」。<br />```<br /><br />所以當你把「~/.bash_profile」拿掉。<br /><br />* 當「登入」的時候,會直接執行「~/.profile」,<br />然後「~/.profile」裡面的程式碼,會執行「~/.bashrc」。<br />,所以「登入」的時候,是會執行「.bashrc」。<br /><br />* 當在「X Window 開 Terminal」的時候,不會執行「~/.profile」,但會執行「~/.bashrc」。<br /><br />以上的前提,「預設的shell」是使用「bash」。<br /><br />所以,若「~/.bash_profile」不存在,就都會執行「.bashrc」。鵝從未在裏面https://www.blogger.com/profile/05998704176013859038noreply@blogger.comtag:blogger.com,1999:blog-3261601569262268959.post-4815756384288943292015-04-17T18:34:39.262+08:002015-04-17T18:34:39.262+08:00
我要表達的是
```
我測試的結果,若「~/.bash_profile」不存在,就都會執行「.b...<br />我要表達的是<br /><br />```<br />我測試的結果,若「~/.bash_profile」不存在,就都會執行「.bashrc」。<br />```<br /><br />所以當你把「~/.bash_profile」拿掉。<br /><br />* 當「登入」的時候,會直接執行「~/.profile」,<br />然後「~/.profile」裡面的程式碼,會執行「~/.bashrc」。<br />,所以「登入」的時候,是會執行「.bashrc」。<br /><br />* 當在「X Window 開 Terminal」的時候,不會執行「~/.profile」,但會執行「~/.bashrc」。<br /><br />以上的前提,「預設的shell」是使用「bash」。<br /><br />所以,若「~/.bash_profile」不存在,就都會執行「.bashrc」。<br /><br /><br />====================================================<br /><br /><br />而你的方式,因為「~/.bash_profile」存在。<br /><br />* 「登入的時候」,執行「~/.bash_profile」,然後你在「~/.bash_profile」,再加入執行「. ~/.bashrc」。<br /><br />* 在「X Window 開 Terminal」的時候,執行「.bashrc」。<br /><br /><br />所以你的方式,其實是一樣的。<br />只不過「~/.profile」換成「~/.bash_profile」。<br /><br /><br />附註: 可以在這些script,加入「echo」訊息,測試的時候,就可以看到執行順序了。 <br /><br />====================================================<br /><br />所以有一種方式, 可以把「.bash_profile」拿掉。<br />然後自己寫的script,寫在另一個檔,另外命名,不要叫「.bash_profile」。<br />然後在「.bashrc」去執行。<br /><br />另外你也可以仿造「/etc/profile」,<br />裡面「if [ -d /etc/profile.d ]; then」哪一段,<br />寫在「~/.bashrc」裡。<br />就會自動執行某個資料夾裡的script檔案。<br /><br /><br />以上參考<br />====================================================<br /><br /><br /><br />:-)<br /><br /><br /><br /><br /><br /><br />鵝從未在裏面https://www.blogger.com/profile/05998704176013859038noreply@blogger.comtag:blogger.com,1999:blog-3261601569262268959.post-4423063793633076522015-04-17T10:27:29.778+08:002015-04-17T10:27:29.778+08:00Hello,
謝謝提供資訊息。
不過,阿舍這篇主要寫的是在 X Window 裡開終端機的情況下,...Hello,<br /><br />謝謝提供資訊息。<br />不過,阿舍這篇主要寫的是在 X Window 裡開終端機的情況下, ~/.profile 似乎只會在登入時讀取,另外再開終端機就不會再讀了哩 !...<br /><br />供參囉 ! ...Arthurhttps://www.blogger.com/profile/07808606363556069115noreply@blogger.comtag:blogger.com,1999:blog-3261601569262268959.post-29549376791105762972015-04-16T16:38:47.452+08:002015-04-16T16:38:47.452+08:00$ cat ~/.profile
可以看到上方的註解「This file is not read ...$ cat ~/.profile<br /><br />可以看到上方的註解「This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login<br />exists.」<br /><br />加上下方還有一段程式碼-「(# if running bash)以下」。<br /><br />我測試的結果,若「~/.bash_profile」不存在,就都會執行「.bashrc」。<br /><br /><br /><br /># ~/.profile: executed by the command interpreter for login shells.<br /># This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login<br /># exists.<br /># see /usr/share/doc/bash/examples/startup-files for examples.<br /># the files are located in the bash-doc package.<br /><br /># the default umask is set in /etc/profile; for setting the umask<br /># for ssh logins, install and configure the libpam-umask package.<br />#umask 022<br /><br /># if running bash<br />if [ -n "$BASH_VERSION" ]; then<br /> # include .bashrc if it exists<br /> if [ -f "$HOME/.bashrc" ]; then<br /> . "$HOME/.bashrc"<br /> fi<br />fi<br /><br /># set PATH so it includes user's private bin if it exists<br />if [ -d "$HOME/bin" ] ; then<br /> PATH="$HOME/bin:$PATH"<br />fi<br />鵝從未在裏面https://www.blogger.com/profile/05998704176013859038noreply@blogger.com