6

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 [email protected] '/some/command -<here_i_want_to_have_value_of_$MY_VAR_variable>'

Thanks!

1
  • Double "'s are your friend here. Commented Oct 11, 2011 at 12:30

2 Answers 2

12

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 [email protected] '/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.

Sign up to request clarification or add additional context in comments.

Comments

5

Use double quotes around the command:

ssh -i /ebs/keys/test [email protected] "/some/command $MY_VAR"

The local shell will expand the variable within double quotes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.