我有一个bash脚本,要求使用" read -s"来输入密码。通过期望运行脚本将密码回显给终端。奇怪的是,它可以按照预期的方式运行,每5次运行一次,但大部分时间都没有。有没有可靠的方法来禁用它?
#!/bin/bash
read -p 'login name? ' name
read -s -p 'password? ' pass
read -p $'\nfavorite color? ' color
echo -e "$name\n$pass\n$color"
#!/usr/bin/expect -f
spawn -noecho ~/tmp/login_test
expect "login name? " {send "gordon\r"}
expect "password? " {
#stty -echo -- This doesn't work
#log_user 0 -- This doesn't work either
send "gr33d\r"
#log_user 1
#stty echo
}
expect "favorite color? " {send "green\r"}
expect eof {exit}
> ~/tmp/login_test
login name? gordon
password?
favorite color? green
gordon
gr33d
green
> ~/tmp/expect_test
login name? gordon
password? gr33d
favorite color? green
gordon
gr33d
green
答案 0 :(得分:0)
想出来!解决方案是睡1个小时......
#!/usr/bin/expect -f
spawn -noecho ~/tmp/login_test
expect "login name? " {send "gordon\r"}
expect "password? " {sleep .001; send "gr33d\r"}
expect "favorite color? " {send "green\r"}
expect eof {exit}