简体   繁体   English

使用echo命令将别名写入bashrc文件

[英]writing alias to bashrc file using echo command

Is it possible to write an "alias to .bashrc" file using echo command in Terminal to make the alias permanent?. 是否可以在终端中使用echo命令将“ alias to .bashrc”文件写入文件,以使别名永久化?

ie echo "alias $NAME='$DEFINTION'" >> ~/.bashrc echo "alias $NAME='$DEFINTION'" >> ~/.bashrc

yes it is. 是的。 only bash'es launched after writing the file will be affected. 只有在写入文件后启动的bash才会受到影响。 to have the alias defined in your current bash session, you need to run alias $NAME='$DEFINTION' in that session before/after adding it to the bashrc. 要在当前bash会话中定义别名,您需要在将alias $NAME='$DEFINTION'添加到bashrc中之前/之后在该会话中运行alias $NAME='$DEFINTION'

Yes but you should also make sure that your login shell would also load it as login shells don't read .bashrc . 是的,但是您还应确保您的登录shell也将其加载,因为登录shell不会读取.bashrc Only interactive shells that are summoned without the -l option reads it. 只有不带-l选项的被召唤的交互式shell才会读取它。

A way to do this is to have this line in your .bash_profile : 一种方法是在您的.bash_profile包含以下行:

[[ -f ~/.bashrc ]] && . ~/.bashrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM