用 here 檔案執行命令
ssh -p 21 example@example.com <<EOF
echo 'printing pwd'
echo "\$(pwd)"
ls -a
find '*.txt'
EOF
$ 被轉義,因為我們不希望它被當前的 shell 擴充套件,即 $(pwd) 將在遠端 shell 上執行。
其他方式:
ssh -p 21 example@example.com <<'EOF'
echo 'printing pwd'
echo "$(pwd)"
ls -a
find '*.txt'
EOF
注意 :結束 EOF 應該在行的開頭(之前沒有空格)。如果需要縮排,如果你使用 <<- 啟動 heredoc,則可以使用製表符。有關詳細資訊,請參閱此處的縮排文件和限制字串示例。