下面的 shell 腳本片段在 sshpass 之外列印環境變數,但不在內部。
#!/bin/bash
[[ $1 = '' ]] && BRANCH="develop" || BRANCH=$1
echo $DESTINATION_FOLDER // prints from env
sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $SERVER <<-'ENDSSH'
echo $DESTINATION_FOLDER // doesn't print anything, output: empty
exit
ENDSSH
我是否缺少通過sshpass傳遞給互動模式的任何選項,以便它可以讀取本地系統中定義的環境變數?
uj5u.com熱心網友回復:
我建議替換'ENDSSH'為ENDSSH以允許 bash 解釋您的 here-document 中的變數。
請參閱:https : //en.wikipedia.org/wiki/Here_document#Unix_shells
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/396795.html
