〜/ .profile,〜/ .bashrc和〜/ .bash_profile没有在新终端上运行启动

Daz*_*sed 9 macos bash terminal .bash-profile

我正在尝试为我的终端创建一个永久别名.我把别名放在我的〜/ .profile,〜/ .bashrc和〜/ .bash_profile文件中,以前是空的.当我启动一个新的终端时,bash不能识别别名,但是如果我找到它们中的任何一个,那就确实如此.为什么打开终端时这些没有运行?我在OSX上.

lch*_*apo 23

较新的 MacOS 版本使用 zsh 作为终端和 iTerm2 的默认 shell。运行echo $SHELL以确认您是否属于这种情况。

Zsh.zshrc在 shell 启动时查找文件,因此要在获取 bash 配置文件内容的同时继续使用 zsh,您可以运行以下命令:

echo "source ~/.bash_profile" >> ~/.zshrc
Run Code Online (Sandbox Code Playgroud)

打开一个新的终端窗口以使更改生效。


pti*_*rno 21

当使用iTermdotfiles加载工作时,需要在这里做两件事.

首先,您应该将以下内容添加到您的 .bash_profile

[[ -s ~/.bashrc ]] && source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

其次,您需要确保在iTerm首选项中,终端设置为启动登录shell.

iTerm首选项

希望这可以帮助!


小智 12

使用默认的mac终端,对我有用的是添加一个命令,在启动时运行以获取我的.bash_profile.

首选项>配置文件>启动>添加命令'source~/.bash_profile'

Mac终端首选项窗口截图

可能会被认为有点hacky,但它确实有把戏.


Meg*_*dad 5

添加source ~/.profile到我的.bash_profile工作对我来说。