I have two scripts to run in local computer shell The first script is a BASH shell which calls an expect script inside itself The bash shell is as follow
BASH SHELL SCRIPT SaveOnRemote.sh
#!/bin/bash
REMOTE_IP_ADDR="192.168.100.67"
REMOTE_PASS="some_pass_with_whitespaces"
#The following line space is defined {\ }
PC_EXEC_FILE="/home/workspace/prog/Modified\ code/test/test_file"
#The following line space is included in the variable
TARGET_EXEC_FILE="/sd/1/test/test file target dir/target_file"
#Calling the expect script
scp_ToTarget.exp $REMOTE_PASS $REMOTE_IP_ADDR $PC_EXEC_FILE $TARGET_EXEC_FILE
End of BASH script SaveOnRemote.sh
And one more we have scp_ToTarget.exp Tcl or Expect script which is called inside the bash shell
Tcl Expect SCRIPT scp_ToTarget.exp
#!/usr/bin/expect -f
set remote_password [lrange $argv 0 0]
set remote_ipaddr [lrange $argv 1 1]
set src [lrange $argv 2 2]
set dst [lrange $argv 3 3]
set timeout 3
log_user 1
eval spawn scp $src root@$remote_ipaddr:$dst
match_max 100000
#Look for passwod prompt
set timeout 5
expect {
"*?assword:*" {
send $remote_password\r\n
}
}
## End of Tcl Expect SCRIPT scp_ToTarget.exp
This scripts does not work and I get unknown directory/file error
In fact I can not avoid spaces neither in file names nor passwords and even directories and I have to make the scripts work.
As far as I know if I send command like
scp "/tmp/try me.txt" [email protected]:"/sd/no tries/"
it works and I have no problem with white spaces. But as soon as I am in Tcl and add double-quotation to
"$src" or \"$src\" or "'$src'"
none of them make the syntax exactly the way I want, Tcl changes double-quote to braces etc I got stuck in this problem and I have no idea how to fix this problem either in bash or Expect or Tcl
Any good reference or web links for handling different string variables in Bash/Tcl is appreciated Thanks
eval
ineval spawn
-- it will cause your command to not work for parameters with whitespace. – glenn jackman