daniel_e
daniel_e

Reputation: 257

Import remote variable via ssh

I try to import variables of a remote bash script via ssh.

Remote file comlink.sh:

#!/bin/bash

test=1
new=2
ready=1

Local file:

#!/bin/bash

ssh pi@[myIP] "cat /home/pi/comlink.sh"

echo $ready

But the variable has no value. Am I missing something?

Upvotes: 1

Views: 285

Answers (1)

janos
janos

Reputation: 124646

If you are absolutely certain you can trust the content of that file, then you can use eval to execute its content in the current shell, thereby "importing" those variables:

eval "$(ssh pi@[myIP] "cat /home/pi/comlink.sh")"

Upvotes: 1

Related Questions