如何在linux设备上执行远程别名?
主机B已定义别名如何在linux设备上执行远程别名?,linux,Linux,主机B已定义别名 alias command='ps -aef|egrep "a|b"|egrep -v "c|grep|ksh|sshd|ssh|ps |tail|bash|su \-"' 如何从方框A中调用此别名 sshuser@Bbash中的“命令”不起作用。 将其定义为一个函数: mycommand() { ps -aef | \ egrep "a|b" | \ egrep -v "c|grep|ksh|sshd|ssh|ps |tail|bash|su -" }
alias command='ps -aef|egrep "a|b"|egrep -v "c|grep|ksh|sshd|ssh|ps |tail|bash|su \-"'
如何从方框A中调用此别名
sshuser@Bbash中的“命令”
不起作用。
将其定义为一个函数:
mycommand() {
ps -aef | \
egrep "a|b" | \
egrep -v "c|grep|ksh|sshd|ssh|ps |tail|bash|su -"
}
…然后告诉shell在生成远程命令时向该函数发出源代码:
ssh user@B "$(declare -f mycommand); mycommand"
您可以使用别名执行类似操作,但eww:
# define alias locally
alias mycommand='ps -aef|egrep "a|b"|egrep -v "c|grep|ksh|sshd|ssh|ps |tail|bash|su \-"'
ssh user@B bash -s <<EOF
shopt -s expand_aliases # enable aliases on remote shell
$(alias -p) # dump all aliases to remote shell
mycommand # invoke desired alias
EOF
哎哟。这确实应该是一个函数,而不是别名。顺便说一句,
命令
是一个shell内置项,因此您不希望通过定义具有相同名称的其他内容来覆盖它。(您是否在问题的任何地方指定了ksh
)。非常感谢。我将使用bashI,但这并不意味着要把任何人从ksh推开(至少不是真正的David Korn ksh93)——它是一个很好的外壳。性能比bash好得多,bash最近才在功能上有了竞争力(而且还没有完全达到这一点——终于有了namevars,但仍然没有浮点运算)。另一方面,值得为它贴标签,并在提问时提及它。
ssh user@B "$(typeset -f); mycommand"