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