我建议不要将别名直接放在?/ .profile中(在注释中建议). ?/ .profile文件不特定于bash.
您应该将别名放在?/ .bashrc中.
为什么?
> .bashrc被保证特定于bash(或其至少任何将来的变体)
>如果正确设置所有内容,则所有外壳程序都可以遵循类似的约定.因此,您可以拥有.bashrc,.zshrc,.tcshrc,.kshrc等.
>如果您像我一样,喜欢玩所有不同的外壳,您会发现这非常有帮助
如何设定
将以下代码放在?/ .profile中.
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
这将确保?/ .bashrc在且仅当您使用bash时运行.
所以最终,涉及到?/ .profile;但是您仍然可以从所有特定于bash的文件中拥有所有别名(以及其他任何特定于bash的命令)中受益.您需要将其添加到.profile的原因在这里进行了说明:What’s The difference between the different scripts for bash?.
然后将别名和其他命令添加到?/ .bashrc.如果?/ .bashrc尚不存在,请通过触摸?/ .bashrc或vi?/ .bashrc创建它.
记住,每当修改?/ .bashrc时,都要重新应用它.否则,您将看不到更改.为此,请运行以下代码:
source ~/.bashrc