在远程 ssh 命令中传递变量 [英] Passing variables in remote ssh command

查看:136
本文介绍了在远程 ssh 命令中传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用 ssh 从我的机器运行命令并传递环境变量 $BUILD_NUMBER

I want to be able to run a command from my machine using ssh and pass through the environment variable $BUILD_NUMBER

这是我正在尝试的:

ssh pvt@192.168.1.133 '~/tools/myScript.pl $BUILD_NUMBER'

$BUILD_NUMBER 是在进行 ssh 调用的机器上设置的,并且由于远程主机上不存在该变量,因此不会被提取.

$BUILD_NUMBER is set on the machine making the ssh call and since the variable doesn't exist on the remote host, it doesn't get picked up.

如何传递 $BUILD_NUMBER 的值?

推荐答案

如果你使用

ssh pvt@192.168.1.133 "~/tools/run_pvt.pl $BUILD_NUMBER"

代替

ssh pvt@192.168.1.133 '~/tools/run_pvt.pl $BUILD_NUMBER'

在将命令字符串发送到远程主机之前,您的 shell 将插入 $BUILD_NUMBER.

your shell will interpolate the $BUILD_NUMBER before sending the command string to the remote host.

这篇关于在远程 ssh 命令中传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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