本文介绍了.bash_profile中定义的别名在OS X中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.bash_profile中定义了三个别名,但是我的bash shell没有读取它.定义的别名在我的终端中不起作用,并且我无法解决此问题.

I have defined three aliases in my .bash_profile but my bash shell is not reading it. The aliases defined are not working in my terminal and I couldn't resolve this issue.

alias handybook="cd /Users/rsukla/development/repos/handybook/"

此行在.bash_profile内部定义,但在我的shell中不起作用.

This line is defined inside the .bash_profile but it is not working in my shell.

到目前为止我已经尝试过的事情:

  • 我已经创建了.bashrc文件并定义了别名,但它也无法正常工作.

  • I have created .bashrc file and defined the alias but it is also not working.

如果我使用source ~rsukla/.bash_profile,则别名可以正常工作,但我希望永久使用别名,因此我不必每次打开外壳时都使用source

if I used source ~rsukla/.bash_profile then the alias are working fine but I want the alias permanently so I don't have to use source every time I open my shell

有人知道为什么在.bash_profile中定义时alias不能工作吗?

Any idea why the hell the alias are not working in when I define in .bash_profile?

推荐答案

我们仍然不知道为什么别名不会自动加载.

您的别名应从.bash_profile加载.这是OS X中bash的默认行为.

Your aliases should be loaded from the .bash_profile. This is the default behaviour of bash in OS X.

mklement0 在.

打开终端的首选项.您可以使用以下命令指定启动外壳程序的命令:

Open the Preferences of the Terminal. You specify the command you start your shell with:

您可以在每次打开外壳程序时指定要获取的文件,而不必每次手动获取点文件.以下是bash的选项列表:

Instead of manually sourcing your dotfiles every time you can specify which file you want to source when the shell opens. Here is the list of options for bash:

Usage:  bash [GNU long option] [option] ...
    bash [GNU long option] [option] script-file ...
GNU long options:
    --debug
    --debugger
    --dump-po-strings
    --dump-strings
    --help
    --init-file
    --login
    --noediting
    --noprofile
    --norc
    --posix
    --protected
    --rcfile
    --restricted
    --verbose
    --version
    --wordexp
Shell options:
    -irsD or -c command or -O shopt_option      (invocation only)
    -abefhkmnptuvxBCHP or -o option

您可以考虑使用/bin/bash --rcfile alias_file_of_yours或类似的方法.

You might consider using /bin/bash --rcfile alias_file_of_yours or something similar.

作为旁注,我建议您检查山羊.它使您可以轻松管理此类cd别名.

As a side note I do recommend you to check out goat. It lets you manage such cd aliases easily.

我用它,我写了它.

这篇关于.bash_profile中定义的别名在OS X中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:27