ssh 命令执行不考虑 .bashrc |.bash_login |.ssh/rc? [英] ssh command execution doesn't consider .bashrc | .bash_login | .ssh/rc?

查看:50
本文介绍了ssh 命令执行不考虑 .bashrc |.bash_login |.ssh/rc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 ssh 远程执行命令,例如:

I am trying to execute a command remotely over ssh, example:

ssh <user>@<host> <command>

需要执行的命令是别名,定义在.bashrc中,例如

The command which needs to be executed is an alias, which is defined in .bashrc, e.g.

alias ll='ls -al'

那么下面的命令到底应该执行什么:

So what in the end the following command should get executed:

ssh user@host "ll"

我已经发现 .bashrc 只能通过交互式 shell 获取源代码,所以我在 .bash_login 中输入:

I already found out that .bashrc only gets sourced with interactive shell, so in .bash_login I put:

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

而且我还尝试直接在 .bash_login 中定义别名.

and I also tried to define the alias directly in .bash_login.

我还尝试将 .bashrc 的别名定义/来源放在 .bash_profile 和 .ssh/rc 中.但这一切都不起作用.请注意,我无法更改 ssh 命令的调用方式,因为这是某些二进制安装脚本的一部分.我唯一可以修改的是环境.执行 ssh 命令时是否还有其他可能来获取此别名?是否有一些 ssh 配置需要调整?

I also tried to put the alias definition / sourcing of .bashrc in .bash_profile and also in .ssh/rc. But nothing of this works. Note that I am not able to change how the ssh command is invoked since this is a part of some binary installation script. The only thing I can modify is the environment. Is there any other possibility to get this alias sourced when the ssh command is executed? Is there some ssh configuration which has to be adapted?

推荐答案

来自 bash 的手册页:

From the man pages of bash:

当 shell 不是交互式时,别名不会被扩展,除非使用 shopt

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt

有几种方法可以做到这一点,但最简单的方法是将以下行添加到您的 .bashrc 文件中:

There are a couple ways to do this, but the simplest is to just add the following line to your .bashrc file:

shopt -s expand_aliases

这篇关于ssh 命令执行不考虑 .bashrc |.bash_login |.ssh/rc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆