我正在使用带有OS X Yosemite和Zsh的Mac电脑。 不小心删除了以下三个文件的内容: .bashrc .bash_profile .profile 之后,当我打开终端时, Zsh将在上次登录信息下显示失败,这让我感到困惑,并且我想知道原因。
我在系统上找到一个.zlogin文件,其中包含一些与rvm相关的代码。我删除了这些代码,问题解决了!
.bashrc
、.bash_profile
或者.profile
文件的内容,因此这些文件的内容并不重要。您也没有提到删除了哪个.bashrc
、.bash_profile
和.profile
文件... 这些文件存在于您的/Users/username
目录和/etc
目录中。在启动时,Zsh源文件列表在OS X zsh man page(在终端中使用 man zsh
命令)的“STARTUP/SHUTDOWN FILES”部分列出。只有当它们被明确地在默认文件中source
时,才会调用先前提到的文件之一。
Check the contents of /etc/zshenv
(this is the only zsh-specific file in my etc
directory). Mine has only the following:
# system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
Can you log in at all using zsh? If not, can you log in using another shell? You can do this in the OS X Terminal.app by going to Preferences -> General and changing the option for "Shells open with:" from "Default login shell" to Command (fill in another shell, i.e., /bin/bash
or /bin/sh
). If you can log in with any shell, try the following solution from this question:
Looking for the error
All shell output goes to the terminal, so you could just redirect it when starting it. As you are looking for error messages during initialisation, I'd suggest the following procedure:
- Disable the problematic configurations
- Open a terminal
- Check the value of
SHLVL
:echo $SHLVL
- Re-enable the configurations
- Start a new z-shell from within the running shell with
zsh 2> zsh-error.log
, this redirects stderr to the file 'zsh-error.log'.- Check the value of
SHLVL
again. If it is bigger then previous value then exit the current shell (exit
). (Explanation below)- Have a look at 'zsh-error.log' in the current directory.
If 'zsh-error.log' does not show anything, you may want to run
zsh -x 2> zsh-error.log
in step 5 instead. This provides a complete debug output of anything zsh does. This can get quite huge.
As the answer suggests, those logs can get enormous if you are sourcing man files at startup. Just a bare shell should result in a reasonably small log file.
Finally, you can retrieve a list of all the files sourced by zsh on startup by running zsh -o sourcetrace
.