2016-02-26 49 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}\"" 
相关问题