Answer the question
In order to leave comments, you need to log in
How to pass the value of a variable over SSH?
Hi all.
Please tell me if it is possible to pass the value of a variable to a command executed on a remote server via SSH:
With this option, the remote server reads the command without assigning a value to the variable.
Thank you. ssh -p22 [email protected] '$RM -f $LR'
Answer the question
In order to leave comments, you need to log in
ssh -p22 [email protected] "$RM -f $LR"
The local values of RM and LR will be substituted.
Only variables known in advance to the ssh server on the other side, only when using SSH protocol version 2. From man ssh_config:
SendEnv
Specifies what variables from the local environ(7) should be sent to the server. Note that environment passing is only supported for protocol 2. The server must also support it, and the server must be
configured to accept these environment variables. Refer to AcceptEnv in sshd_config(5) for how to configure the server. Variables are specified by name, which may contain wildcard characters. Multiple
environment variables may be separated by whitespace or spread across multiple SendEnv directives. The default is not to send any environment variables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question