使用 EXPECT 的问题是 BASH shell 脚本

Fer*_*SBS 0 bash bash-scripting expect

这是代码(bash脚本):

echo "Pass for router:"
read -s pass


/usr/bin/expect <<EOD
spawn ssh 192.168.10.1 -l root 'opkg list-installed' > list-installed.txt
#echo @pass
expect "*password:*"
send "$pass\r"
interact
EOD
Run Code Online (Sandbox Code Playgroud)

问题是它什么都不返回。它不会创建本地文件“list-installed.txt”

这可能有什么问题?

gle*_*man 5

单引号在expect中没有特殊含义。使用双引号。

此外,使用expect eof而不是interact,因为一旦您输入密码就没有任何实际交互 - 您只是在等待命令完成。