关于.bash_profile,.bashrc,别名应该写在哪里? [英] About .bash_profile, .bashrc, and where should alias be written in?

查看:24
本文介绍了关于.bash_profile,.bashrc,别名应该写在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:.bashrc、.bash_profile 和 .environment 有什么区别?

好像如果我用

alias ls='ls -F'

在 Mac OS X 上的 .bashrc 里面,那么新创建的 shell 将没有那个别名.我需要再次输入 bash 并且该别名将生效.

inside of .bashrc on Mac OS X, then the newly created shell will not have that alias. I need to type bash again and that alias will be in effect.

如果我在托管公司登录 Linux,.bashrc 文件有一个注释行,内容为:

And if I log into Linux on the hosting company, the .bashrc file has a comment line that says:

对于非登录shell

.bash_profile 文件有一个注释说

and the .bash_profile file has a comment that says

用于登录shell

那么别名应该写在哪里呢?怎么区分登录shell和非登录shell?

So where should aliases be written in? How come we separate the login shell and non-login shell?

有些网页说使用 .bash_aliases,但它似乎不适用于 Mac OS X.

Some webpage say use .bash_aliases, but it doesn't work on Mac OS X, it seems.

推荐答案

loginnon-login 分开的原因是因为 .bashrc 文件每次启动 Bash 的新副本时都会重新加载..profile 文件仅在您登录或使用适当的标志告诉 Bash 作为登录 shell 时加载.

The reason you separate the login and non-login shell is because the .bashrc file is reloaded every time you start a new copy of Bash. The .profile file is loaded only when you either log in or use the appropriate flag to tell Bash to act as a login shell.

就个人而言,

  • 我将我的 PATH 设置放入一个 .profile 文件中(因为我有时会使用其他 shell);
  • 我将我的 Bash 别名和函数放入了我的 .bashrc 文件中;
  • 我把这个

  • I put my PATH setup into a .profile file (because I sometimes use other shells);
  • I put my Bash aliases and functions into my .bashrc file;
  • I put this

#!/bin/bash
#
# CRM .bash_profile Time-stamp: "2008-12-07 19:42"
#
# echo "Loading ${HOME}/.bash_profile"
source ~/.profile # get my PATH setup
source ~/.bashrc  # get my Bash aliases

在我的 .bash_profile 文件中.

哦,您需要再次键入 bash 以获取新别名的原因是 Bash 在启动时加载了您的 .bashrc 文件,但它不会重新加载除非你告诉它.您可以通过键入

Oh, and the reason you need to type bash again to get the new alias is that Bash loads your .bashrc file when it starts but it doesn't reload it unless you tell it to. You can reload the .bashrc file (and not need a second shell) by typing

source ~/.bashrc

加载 .bashrc 文件,就像你直接在 Bash 中输入命令一样.

which loads the .bashrc file as if you had typed the commands directly to Bash.

这篇关于关于.bash_profile,.bashrc,别名应该写在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆