tags:

views:

147

answers:

2

Hello,

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; "
+3  A: 

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.

Ignacio Vazquez-Abrams
Whoa! Thanks. +1
Kunal
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!
Kunal
Sure. Just switch them up. `ssh ... 'echo $remote'"$local"`
Ignacio Vazquez-Abrams
+1  A: 

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.

msw
+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.
Kunal