[SSH] Accessing remote directory with user-passed path

Hi everybody,

Currently, I have a script which access a remote computer via SSH, go to a folder already defined in the code and then executes a program in it, just like that:

ssh user@host  << EOI
cd path
./file
EOI

It executes fine, but now I want to pass an argument in the command line call. which is the name of the folder to "cd" to and the name of the file to run. So I tried the following:

dir=  $1
ssh user@host << EOI
cd $dir
pwd
./$1
EOI

, which doesn't work. It's as if after the "ssh user@host << EOI" line the script lost knowledge of the variable $dir as well as $1.

I'm pretty noob in shell scripting, so would you know any way to solve this?

Thanks in advance,
Luiz.

dir=  $1

The spaces between = and $1 stop this from working, which is probably why $dir doesn't work.

When dir is $1, ./$1 won't do what you want, since you want to run ./file, not ./dir

1 Like

You'are right. Now it works.
Thank you very much!

Luiz.