See if the quoting within quotes is causing any issue by turning this into an expect script and running it that way, instead of inline...
File test.exp:
Code:
#!/usr/bin/expect
set hostName [lindex $argv 0]
set filePath [lindex $argv 1]
spawn /usr/bin/scp -q "$filePath" "user@$hostName:$filePath"
set timeout 60
expect {
-re ".*password:.*" { send "myPassword\n"; interact }
eof { exit }
timeout { puts "\n--TIMEOUT!--\n";exit}
}
exit
Then run:
Code:
./test.exp host file
Just curious to see if its kicking out those \n's somewhere because you are doing it inline or whether its coming from scp terminating...