Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variable through ssh doesnt work

Tags:

bash

ssh

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 locally.

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

like image 331
lugte098 Avatar asked Mar 10 '10 12:03

lugte098


2 Answers

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

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

like image 102
orithena Avatar answered Sep 22 '22 10:09

orithena


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.

like image 26
Pascal MARTIN Avatar answered Sep 21 '22 10:09

Pascal MARTIN