Is there a way to have environment variables on a remote host evaluated when using SCP?

For instance, let's say I have $FOO= /mydir on host A; how would I do something like:

scp dogbert@hostA:$FOO/evil-secret-plans.txt .

Of course, $FOO isn't defined on my local machine so the above command doesn't work as it is.

link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

Try it like this:

scp dogbert@hostA:$(ssh dagobert@hostA "echo $FOO")/evil-secret-plans.txt .

A bit of overhead.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.