当我使用ssh时,为什么'export foo = 1'无法读取?


1

我正在尝试在ssh命令中显式设置远程环境变量:

ssh worker-2 "export OPENBLAS_NUM_THREADS=1; echo $OPENBLAS_NUM_THREADS"

奇怪的是,这只打印一个空白行,但是当我在本地运行相同的命令时,它会正确打印1

由于我是明确设置变量,为什么它不能远程工作?

Answers:


4

$OPENBLAS_NUM_THREADSbash在将其发送到远程计算机之前进行本地评估。

你需要逃避$

ssh worker-2 "export OPENBLAS_NUM_THREADS=1; echo \$OPENBLAS_NUM_THREADS"

或使用单引号,这会抑制bash变量评估:

ssh worker-2 'export OPENBLAS_NUM_THREADS=1; echo $OPENBLAS_NUM_THREADS'
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.