1

I am trying to execute unix command using SSH from cygwin. My set of command would navigate to a certain directory, source a particular file. Based on the variables sourced from that file, I would try to launch application. But somehow the variables are not getting sourced as echo does not return any values. Could someone let me know what am I missing here

Contents of the environment variables file (myenv) are

export TEST_DATA="DATA1:DATA2"

and I am executing the following command

$ ssh kunal@kspace "ls; cd /disk1/kunal/env; . ./myenv; echo $TEST_DATA; "

2 Answers 2

3

Double quotes do not inhibit expansion. Use single quotes instead.

That is, the variable is being expanded on your side, not on the server you're SSHing to.

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

2 Comments

is there anyway where I can use both? What I mean is, I have some variables in local machine which I would like to pass to ssh for local expansion. Also depending on the variables file, I would like to echo the variables for which I do not want the local expansion!
Sure. Just switch them up. ssh ... 'echo $remote'"$local"
1

Because $TEST_DATA is in double quotes, its value is being interpolated by your local shell (the one you called ssh in). If you use single quotes it will pass the literal $TEST_DATA across as part of the ssh command to be executed on the far side.

1 Comment

+1! It works with single quotes. However I am looking a way where I can use both kind of variables. One which should be expanded locally and another should be expanded remotely.

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.