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

查看:328
本文介绍了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?

推荐答案

从庆典的手册页:

别名没有扩展的时候shell不是交互式的,除非 expand_aliases 外壳选项设置使用禁用了javascript

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天全站免登陆