I need to use a variable within a backtick expression embedded in a rcp
invocation.
My initial attempt:
#!/bin/sh
release=1
rcp myserver.foo.com:'`ls -t /path/to/my/${release} | head -n 1`' .
I suppose this is failing because the back-tick expression is being executed on myserver.foo.com
which doesn't have a release
variable, so the argument to my ls
command is just /path/to/my/
.
I read that typically the eval
command can be used to (I think) pre-process the back-tick expression. When I try that approach:
#!/bin/sh
release=1
rcp myserver.foo.com:'`ls -t /path/to/my/eval ${release} | head -n 1`' .
...the backtick expression is just executed as /path/to/my/eval
.
How I can use variables in my backtick expression in this context?
To be clear: I'm attempting to have the code in back-ticks run on the remote server, not locally (but I need ${release}
to be resolved locally before-hand)