命令文件:Expect + Title。我怎么能这样做?

时间:2016-10-14 12:33:22

标签: bash command title expect

如何使用expecttitle执行命令文件(macOS)或类似命令(GNU / Linux)?

现在我用它:

#!/usr/bin/expect -f

set timeout -1

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

spawn ssh username@IP
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 username@IP
expect "?"
send "yes\r"
expect "assword:"
send "thepassword\r"
expect "thenamemachine:~#"
send "bash <(curl -s aFile.sh)\r"
interact

1 个答案:

答案 0 :(得分:1)

您需要在expect脚本中使用语法,而不是shell。你想要:

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

此外,您无需与rm -rf进行任何互动,因此请使用exec代替spawn

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