开发者

Bash eval inside quotes

开发者 https://www.devze.com 2023-04-08 04:52 出处:网络
I have a bash script which takes one parameter and does something like this: ssh -t someserver \"setenv DISPLAY $1; /usr/bin/someprogram\"

I have a bash script which takes one parameter and does something like this:

ssh -t someserver "setenv DISPLAY $1; /usr/bin/someprogram"

How can I force bash to substitute in the $1 instead of passing the literal characters "$1" as the display variabl开发者_如何学Pythone?


Based on your comment on sehe's answer, it sounds like you just want the remote command to use the local X display — so that the program is running on your remote server (someserver) but being displayed on the machine you ran the ssh command on.

This can be done by just passing -X, e.g.

ssh -X someserver /usr/bin/someprogram

For some reason, this doesn't work with a few programs, for example evince. I'm not really sure why. I'm pretty sure that evince is the only app I've had trouble forwarding back over an SSH connection.

If this isn't what you're aiming to do, please explain.


Edit Are you aware of

ssh -X ...
ssh -Y ...

which already support X forwarding out of the box? Also look at

xhost +

in case you need to increase permissions to 'guests'.

If you want to forward non-standard X display address, you could always use

DISPLAY=localhost:3 ssh -XCt user@remote xterm

Bonus: to make ssh background after authentication, add '-f'

What locally? That should already work as shown. Remotely? escape the $: \$

However, I'm not sure where the command would be taking it's arguments ($1) from

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号