不完全是。简单说:Ubuntu 的 shell alias 只在“使用该 shell 的交互式环境”里生效,并不严格限于“终端窗口”,但也不会跨 shell、跨会话、跨程序自动生效。
下面分几种情况说清楚:
alias 是 bash / zsh 等 shell 提供的功能,不是操作系统级别的概念。
所以:
一般你写在:
~/.bashrc
里的 alias,只在:
时生效。
以下情况通常不可用:
ssh command 非登录非交互执行例如:
ssh user@host ls
这里的 ls 不会加载 alias。
只要是 bash 交互环境就行,比如:
都能用 alias。
bash 用户:
~/.bashrc
zsh 用户:
~/.zshrc
在脚本中:
shopt -s expand_aliases
source ~/.bashrc
或者在脚本里直接用函数更稳妥。
mycmd() {
command arg1 arg2
}
函数比 alias 更可控、更安全。
Ubuntu 的 alias 不限于“终端”,但仅限于“对应 shell 的交互式环境”,不会全局、跨 shell、跨程序自动生效。
如果你愿意,我可以帮你判断: