I have two machines, A and B. I need to execute a script which is located in B by SSHing there from A.
In order for the script to run I also need to export a variable. If I just SSH and export the variable and then try again to SSH and execute the script, the variable is no longer available.
Is there a way to export the variable and make it available in the same session with the script?
I was hoping for something like this (but it doesn't work):
ssh root@B export PATH=$PATH:/add/stuff/here && runScript.sh
Even if I do the following, the path isn't updated:
ssh root@B export PATH=$PATH:/add/stuff/here && echo $PATH
You're slightly wrong in passing the third argument. In the command you've provided you pass instructions as many arguments, and, additionally, you echo
local $PATH
. You must pass the whole command as one argument, in single quotes.
Instead of
ssh root@B export PATH=$PATH:/add/stuff/here && echo $PATH
Which is:
(ssh + root@B + export + PATH=...) && (echo + $PATH)
You should do:
ssh root@B 'export PATH="$PATH:/add/stuff/here" && echo $PATH'
Which is:
ssh + root@B + '(export + PATH=..) && (echo $PATH)'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments