Skip to content
Advertisement

How to access local variables in remote server using ssh [closed]

I am trying to access my local variable in remote server. Which command should I use.

Ex. cmd:

SERVER 1
VAR=2
ssh unix-user@remote-server-name "bash abc.sh"

REMOTE SERVER:

cat abc.sh
echo $VAR

output should get 2.

Advertisement

Answer

Set the variable directly on the remote side:

ssh unix-user@remote-server-name "export VAR=2; bash abc.sh"
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement