开发者

execute one-line ssh command with variable from local environment

开发者 https://www.devze.com 2023-04-12 00:25 出处:网络
Let\'s pretend that in the current shell, I have a variable. $ echo $MY_VAR $ 2 What I want is to pass the value of this variable to an argument of a command I\'m executing through ssh, like:

Let's pretend that in the current shell, I have a variable.

$ echo $MY_VAR
$ 2

What I want is to pass the value of this variable to an argument of a command I'm executing through ssh, like:

ssh -i /ebs/keys/test root@some.ip '/some/command -<here_i_want_to_have_value_of_$MY_VAR_variable&g开发者_StackOverflow中文版t;'

Thanks!


Assuming you cannot use double quotes around the entire command to ssh, you could break just $MY_VAR out like this:

ssh -i /ebs/keys/test root@some.ip '/some/command -'"$MY_VAR"

If the rest of the command to ssh does not contain tokens that will be interpreted within double quotes, you can enclose the entire command in double quotes instead of single.


Use double quotes around the command:

ssh -i /ebs/keys/test root@some.ip "/some/command $MY_VAR"

The local shell will expand the variable within double quotes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号