小编Mat*_*att的帖子

非交互式 shell 扩展别名

当我运行如下命令时,我无法获取别名以扩展我的主机帐户:

ssh user@server "bash -c \"alias\""
Run Code Online (Sandbox Code Playgroud)

我的 .bashrc 文件是:

echo .bashrc
# .bashrc

shopt -s expand_aliases

# Source global definitions (commenting this out does nothing)
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
alias php="php55"
alias composer="php ~/bin/composer.phar"
Run Code Online (Sandbox Code Playgroud)

当我运行上面的 ssh 命令时,我确实看到了“.bashrc”回显。但是如果我尝试运行别名,我什么也得不到。

我可以尝试“bash -ic”,但这实际上是在我无法轻易更改的脚本中,我想知道为什么这不起作用。

输出 ssh user@server "bash -c \"shopt\""

.bashrc
autocd          off
cdable_vars     off
cdspell         off
checkhash       off
checkjobs       off
checkwinsize    off
cmdhist         on
compat31        off
compat32        off
compat40        off
dirspell        off
dotglob …
Run Code Online (Sandbox Code Playgroud)

bash ssh alias bashrc

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

alias ×1

bash ×1

bashrc ×1

ssh ×1