实例如下:
#!/usr/bin/expect
set username [lindex $argv 0]
set userpass [lindex $argv 1]
# spawn the htpasswd command process
spawn passwd $username
# Automate the 'New password' Procedure
expect "New password:"
send "$userpass\r"
expect "Retype*"
send "$userpass\r"
expect eof
chmod +x scriptname
./scriptname username password