Bash变量始终为空

时间:2016-01-02 15:55:56

标签: linux bash heredoc

以下bash脚本的结果是输出中的“空行”

ssh dev@my_service <<EOF
  START_SERVICE_TIME_IS_UP=124
  echo $START_SERVICE_TIME_IS_UP
  exit  
EOF

无法理解为什么。我希望在输出中看到“124”。远程服务器正在运行Red Hat linux。

2 个答案:

答案 0 :(得分:7)

here-doc中的变量由本地shell扩展,除非引用here-doc。将结束标记放在引号中引用here-doc。

ssh dev@my_service <<'EOF'
  START_SERVICE_TIME_IS_UP=124
  echo $START_SERVICE_TIME_IS_UP
  exit  
EOF

答案 1 :(得分:-2)

始终使用&#34;&#34; echo&#34; $ START_SERVICE_TIME_IS_UP&#34; 一些方便使用echo https://github.com/united-bashers/mkbash

相关问题