开发者

Passing variable through ssh doesnt work

开发者 https://www.devze.com 2022-12-22 23:34 出处:网络
I\'m trying to pass a variable through a ssh connection, like this: working_dir=\"/home/user/some_dir/\"

I'm trying to pass a variable through a ssh connection, like this:

working_dir="/home/user/some_dir/"

ssh $USER@some_host 'qsub $working_dir/some_file.txt'

The connection itself is established, but this code gives me the following error:

working_dir: Undefined variable.

This could be explained, by the fact that the remote machine doesn't have the variable $working_dir since it was defined local开发者_Go百科ly.

Is there a way of getting the value in the command locally?


Try using double quotes, that should evaluate the variable locally:

ssh $USER@some_host "qsub $working_dir/some_file.txt"


You are using a single-quoted string -- and I suppose variables are not interpolated inside of those.

What if you try with a double-quoted string ?
Like this :

ssh $USER@some_host "qsub $working_dir/some_file.txt"

With that, the $working_dir variable should be interpolated on your end -- and its value sent via the ssh connection.

0

精彩评论

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

关注公众号