Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
执行此命令时:
user@local:~ >ssh user@remote " export myvar=myvalue ; echo myvar=$myvar ; "
我得到输出:
myvar=
直接在远程机器上运行时,我得到了预期的结果:
user@remote:~ > export myvar=myvalue ; echo myvar=$myvar ;
输出:
myvar=myvalue
那么如何在 ssh 命令中设置变量呢?
That's because you're using double quotes, so the variable is being expanded on your local machine before ssh is even invoked. Use single quotes:
ssh user@remote 'export myvar=myvalue ; echo myvar=$myvar'