Chinaunix
标题:
远程主机上执行alias的命令 别名
[打印本页]
作者:
zf0702
时间:
2016-05-24 12:07
标题:
远程主机上执行alias的命令 别名
本地主机A
远程主机B
以下命令已经添加在~/.bashrc文件中
alias cmd="command -a"
在本地主机A上执行一下命令:
A>ssh user@B "cmd"
报错:bash: cmd :command not found
请问如何才能在A机器上远程执行B机器上的alias过的命令(别名)
作者:
q1208c
时间:
2016-05-24 12:15
ssh 直接执行命令的时候, 可能没有走到 login这一步, 所以,rc 和 profile 都没有被加载。
建议直接使用原始命令吧。
作者:
ziyunfei
时间:
2016-05-24 12:27
ssh user@B <<EOF
heredoc> shopt -s expand_aliases
heredoc> cmd
heredoc> EOF
复制代码
作者:
ziyunfei
时间:
2016-05-24 12:28
或者在远程机的 .bash_profile 里加上 shopt -s expand_aliases
然后直接用 herestring
ssh user@B <<< cmd
复制代码
作者:
zf0702
时间:
2016-05-24 16:28
谢了,这个方法确实可以的。
回复
4#
ziyunfei
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2