我已经努力寻找能够帮助解决这个问题的答案,但我无法弄清楚如何将反斜杠发送到期望声明中。以下是我的代码。当它试图执行ssh语句时,它在我需要的单引号之前永远不会有反斜杠。
#!/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 hdiuser@${CLUSTER_NAME}-ssh.azurehdinsight.net "mkdir -p /home/hdiuser/${RUN_NAME}"
expect password: { send "XXXXXXXX"; exp_continue }
EOD
done
这总是产生以下结果:
spawn ssh hdiuser@examplecluster-ssh.azurehdinsight.net 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 expect语句中保留反斜杠?
答案 0 :(得分:2)
Add three slashes before the single quote when declaring the array:
declare -a sparr=("Wilson\\\'s_Warbler")
Also put escaped double quotes around your destination path, so:
spawn ssh hdiuser@${CLUSTER_NAME}-ssh.azurehdinsight.net "mkdir -p \"/home/hdiuser/${RUN_NAME}\""