文章目錄
- 令人蛋疼的事
- 百因必有果
- 你的報應就是我
- 其他
- 參考資料
如果你懶得看整個程序,就直接:
編輯.zshrc檔案,在最后追加一個source命令
zhenghui@192 ~ %
zhenghui@192 ~ % cat ~/.zshrc
#每次用戶進入之后使bash_profile生效
source ~/.bash_profile
zhenghui@192 ~ %
令人蛋疼的事

換了mac也一段時間了,mac到手后,第一件事就是配置jdk和maven環境變數,但是每次想在命令列下使用到java明令或者maven明令的時候,都會提示沒有安裝jdk或者找不到JAVA_HOME變數,
然后不得不手動執行:source ~/.base_profile
然后再此執行之前的命令就可以了,
就這樣持續了N次,
今天跟群友們討論了一番,原來不是我自己遇到了這個問題,決定一探究竟,終于解決了,
百因必有果
我相信這一切肯定是有原因的,肯定不是命中注定,
既然mac在啟動后用戶登陸進來沒有執行~/.bash_profile檔案,說明就沒有默認加載這個唄,
而配置“bash_profile”這個檔案,是我們在Linux下的習慣,
帶著好奇心,百度了一下,網上說跟默認shell有關系,
那就查一下唄,可以使用echo $0來查看
這是Centos下的:
可以看到默認shell是bash
[root@TrueDei ~]#
[root@TrueDei ~]# echo $0
-bash
[root@TrueDei ~]#
[root@TrueDei ~]#
這是mac下的:
而在mac下的默認shell是zsh,
zhenghui@192 ~ % echo $0
-zsh
zhenghui@192 ~ %
bash加載組態檔的順序:
登陸式SHELLL組態檔加載順序:/etc/profile > .bash_profile > .bash_login > .profile > .bash_logout.
非登錄式SHELL組態檔加載順序:/etc/bash.bashrc > .bashrc
注: 先加載的組態檔的配置,可能會被后加載的配置所覆寫
zsh加載組態檔的順序:
通過查看zsh檔案中組態檔,有下列這些:
$ZDOTDIR/.zshenv
$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout
${TMPPREFIX}* (default is /tmp/zsh*)
/etc/zshenv
/etc/zprofile
/etc/zshrc
/etc/zlogin
/etc/zlogout (installation-specific - /etc is the default)
而加載順序是這樣的:
/etc/zshenv
~/.zshenv
/etc/zprofile
~/.zprofile
/etc/zshrc
~/.zshrc
/etc/zlogin
~/.zlogin
~/.zlogout
/etc/zlogout
我們比較關心的是用戶下的,過濾一些我們不必關心的:
~/.zshenv
~/.zprofile
~/.zshrc
~/.zlogin
~/.zlogout
你的報應就是我
在bash中我們可以看到咱們熟悉的“bash_profile”組態檔,但是在zsh中始終沒有看到“bash_profile”的影子,
那我們就去找一下mac下zsh用戶下的這些組態檔吧,
可以看到只有“.zshrc”檔案,可以得出一個解決,那么用戶下默認執行的肯定就是“.zshrc”檔案了
zhenghui@192 ~ %
zhenghui@192 ~ % ls -a |egrep -e "zshenv|zprofile|zshrc|zlogin|zlogout"
.zshrc
zhenghui@192 ~ %
zhenghui@192 ~ %
編輯.zshrc檔案,在最后追加一個source命令
zhenghui@192 ~ %
zhenghui@192 ~ % cat ~/.zshrc
#每次用戶進入之后使bash_profile生效
source ~/.bash_profile
zhenghui@192 ~ %
重啟一下mac,發現可以了,
其他
我們還可以查看系統中已有的shell
zhenghui@192 ~ %
zhenghui@192 ~ % cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
zhenghui@192 ~ %
zhenghui@192 ~ %
還可以更改默認shell
通過chsh命令改變當前的shell,當前的shell 設定為/bin/bash,改變shell的設定/bin/csh,
通過 -s 引數改變當前的shell設定
先說好::::具體我沒嘗試過,這是從百度上找的,大家如果嘗試的話,導致電腦廢了,不要賴我哈,
zhenghui@192 ~ % chsh -s /bin/csh /bin/csh
參考資料
https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_010.html
http://wxnacy.com/2018/10/08/zsh-startup-files/ 資料
http://zsh.sourceforge.net/Doc/Release/zsh_toc.html zsh檔案
http://zsh.sourceforge.net/Doc/Release/Files.html#Files 組態檔
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/273629.html
標籤:其他
上一篇:zabbix監控郵箱報警
