SSH 后别名未知

SSH 后别名未知
$ grep alias ~/.bashrc
# User specific aliases and functions
. ~/.alias

$ grep mydiff ~/.alias
alias mydiff='diff --ignore-space-change --ignore-blank-lines --side-by-side --suppress-common-lines'

$ alias mydiff
alias mydiff='diff --ignore-space-change --ignore-blank-lines --side-by-side --suppress-common-lines'

$ ssh -q localhost 'alias mydiff'
alias mydiff='diff --ignore-space-change --ignore-blank-lines --side-by-side --suppress-common-lines'

$ ssh -q localhost 'mydiff'
bash: mydiff: command not found

为什么“mydiff”无法通过 SSH 访问?谢谢

答案1

man bash(1)

   Aliases  are not expanded when the shell is not interactive, unless the
   expand_aliases shell option is set using shopt (see the description  of
   shopt under SHELL BUILTIN COMMANDS below).

将以下行添加到您的.bashrc文件中:

shopt -s expand_aliases

或者:

[alexus@wcmisdlin02 ~]$ ssh 0 'bash -c ll | head -1'
bash: ll: command not found
[alexus@wcmisdlin02 ~]$ ssh 0 'bash -ci ll | head -1'
bash: no job control in this shell
total 8612
[alexus@wcmisdlin02 ~]$ 

相关内容