如何使别名永久存在?

时间:2020-08-05 21:02:23

标签: bash command-line alias nano

我想创建一个别名python =“ python3”。我通过使用 nano〜/ .bash_profile,然后键入:alias python =“ python3”,然后保存。然后我写:source〜/ .bash_profile覆盖更改。但是该别名仅在我所在的终端会话中有效。当我开始新的终端会话时,我必须为别名python =“ python3”编写源〜/ .bash_profile,以使其生效。

4 个答案:

答案 0 :(得分:0)

〜/ .bashrc文件中是否有类似

的命令?
source ~/.bash_profile

. ~/.bash_profile

如果没有,则必须添加

无论如何,通常的做法是创建〜/ .bash_aliases以使用别名,然后像下面这样在〜/ .bashrc中获取它:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

答案 1 :(得分:0)

.bash_profile仅用于登录Shell。 GUI终端应用程序通常会启动仅使用.bashrc的非登录Shell。我个人将所有配置都放在.bashrc中,而我的~/.bash_profile只有一行:

source ~/.bashrc

答案 2 :(得分:0)

bp的手册页会告诉您,

onTask = (pro, tas) => { fetch('https://bpm.***********.or.id/api/1.0/**********/cases/', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'Authorization': 'Bearer ' + this.state.token, }, body: JSON.stringify({ 'pro_uid': pro, 'tas_uid': tas, }), }) .then((response) => response.json()) .then((responseJson) => { console.log(responseJson); //here the data appears this.setState({ dataApp: responseJson, }); console.log(this.state.dataApp); //but here does not appear any data }); 仅由交互式登录 Shell提供。如果您希望在交互式非登录外壳程序中也可以使用它,建议您将别名定义放在单独的文件中(例如:~/.bash_profile),并从两个{ {1}}和~/.bash_interactive

答案 3 :(得分:-1)

要使别名永久存在,您必须将其设置在启动终端时读取的文件中。即尝试将您的行alias python=python3添加到~/.bashrc~/.profile~/.bash_profile中进行远程登录。如果要为所有用户执行该命令,请将其放入/etc/bash.bashrc中。通常,别名可以保留在~/.bash_aliases文件中,并且该文件由~/.bashrc加载。如果在旧版本的Ubuntu上运行,请记住取消注释~/.bashrc中的以下行以启用~/.bash_aliases。在Ubuntu 11.04和更高版本上,该功能已启用:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

别名命令将在任何新终端上可用。要在任何现有终端上使用别名命令,需要从该终端获取~/.bashrc作为

source ~/.bashrc
相关问题