命令文件:Expect+Title。我怎样才能做到这一点?

Command file: Expect+Title. How can I do this?

如何使用 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 "3]0;$title[=11=]7"

因为这行不通

#!/usr/bin/expect -f

title='My first title'
echo -n -e "3]0;$title[=12=]7"

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

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

set title "My first title"
send_user "3]0;$title[=10=]7"

此外,您不需要与 rm -rf 进行任何互动,因此请使用 exec 而不是 spawn

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