下面是我的脚本:
#!/usr/bin/expect
echo "enter unique id"
read test
mkdir -p /evoting_test/$test
spawn scp -r abc@10.150.10.104:/shareddata/was/l1/*.pdf /rishabh/$test/
set pass "abc123"
expect {
password: {send "$pass\r"; exp_continue}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
invalid command name "echo"
while executing
"echo "enter uNIQUE id" "
(file "./scp_test.sh" line 2)
Run Code Online (Sandbox Code Playgroud)
它不是从用户读取变量并在命令中使用该变量
做到这一点的“期望”方式是:
send_user "enter unique id: "
expect_user -re "(.*)\n"
set test $expect_out(1,string)
send_user "you said $test\n"
Run Code Online (Sandbox Code Playgroud)
由于 expect 扩展了tcl,您可以使用:
puts -nonewline "enter unique id: "
flush stdout
gets stdin test
puts "you said $test"
Run Code Online (Sandbox Code Playgroud)
此外,您会收到错误消息mkdir——这是一个外部命令。您可以执行以下操作之一:
exec mkdir -p /evoting_test/$test # invoke the external command
file mkdir /evoting_test/$test # use the builtin
Run Code Online (Sandbox Code Playgroud)
见http://tcl.tk/man/tcl8.6/TclCmd/file.htm
| 归档时间: |
|
| 查看次数: |
5123 次 |
| 最近记录: |