the_skua
the_skua

Reputation: 1291

Keeping Backslash Escaped Single Quote in Bash EOD for Expect

I've tried hard to find an answer that helps me with this problem, but I can't figure out how to send a backslash through to an expect statement. Below is my code. When it attempts to execute the ssh statement, it never has the backslash before the single quote I need.

#!/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

This always produces the following:

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

How do I keep the backslash in the ssh expect statement?

Upvotes: 1

Views: 169

Answers (1)

dvs
dvs

Reputation: 12422

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}\""

Upvotes: 2

Related Questions