2016-02-26 98 views
1

我試過很難找到一個答案,可以幫助我解決這個問題,但我無法弄清楚如何發送一個反斜槓到期望聲明。以下是我的代碼。當它試圖執行ssh語句時,它在我需要的單引號之前從不具有反斜槓。保持反斜槓單引號在Bash EOD的期待

#!/bin/bash 
CLUSTER_NAME=examplecluster 
SAMPLE_N=100 
REP_N=1 

declare -a sparr=('Wilson'"\'"'s_Warbler') 

for sp in "${sparr[@]}" 
do 
RUN_NAME=${sp}_${SAMPLE_N}_${REP_N} 
cd /home/shared/stemhwf/stem_hwf/runs/${RUN_NAME}/data 

/usr/bin/expect <<EOD 
set timeout -1 
spawn ssh [email protected]${CLUSTER_NAME}-ssh.azurehdinsight.net "mkdir -p /home/hdiuser/${RUN_NAME}" 
expect password: { send "XXXXXXXX"; exp_continue } 
EOD 
done 

這總是產生如下:

spawn ssh [email protected] mkdir -p /home/hdiuser/Wilson's_Warbler_100_1 

bash: -c: line 0: unexpected EOF while looking for matching `'' 
bash: -c: line 1: syntax error: unexpected end of file 

如何保持在SSH反斜線期待聲明?

+0

我知道,包括反斜槓作品,因爲我從命令行手動測試過它。 'ssh [email protected]「mkdir -p/home/hdiuser/Wilson \'s_Warbler_100_1」' –

回答

2

單引號前加三個斜槓聲明數組的時候:

declare -a sparr=("Wilson\\\'s_Warbler")

也把逃脫在你的目標路徑雙引號,所以:

spawn ssh [email protected]${CLUSTER_NAME}-ssh.azurehdinsight.net "mkdir -p \"/home/hdiuser/${RUN_NAME}\"" 
相關問題