2016-10-14 48 views
1

如何使用expecttitle执行命令文件(macOS)或类似的(GNU/Linux)?命令文件:预期+标题。我怎样才能做到这一点?

现在我用这个:

#!/usr/bin/expect -f 

set timeout -1 

spawn rm -rf /path/to/.ssh/known_hosts 

spawn ssh [email protected] 
expect "?" 
send "yes\r" 
expect "assword:" 
send "thepassword\r" 
expect "thenamemachine:~#" 
send "bash <(curl -s aFile.sh)\r" 
interact 

但我怎么可以添加此

title='My first title' 
echo -n -e "\033]0;$title\007" 

因此不起作用

#!/usr/bin/expect -f 

title='My first title' 
echo -n -e "\033]0;$title\007" 

set timeout -1 

spawn rm -rf /path/to/.ssh/known_hosts 

spawn ssh [email protected] 
expect "?" 
send "yes\r" 
expect "assword:" 
send "thepassword\r" 
expect "thenamemachine:~#" 
send "bash <(curl -s aFile.sh)\r" 
interact 

回答

1

您需要使用语法期望脚本,而不是shell。你想:

set title "My first title" 
send_user "\033]0;$title\007" 

而且,你不需要有任何rm -rf互动,所以使用exec代替spawn

exec rm -rf /path/to/.ssh/known_hosts 
+0

非常感谢您!并非常感谢** exec **提示! – DylanDog

相关问题