格式
#!/bin/bash
shell 语句
/usr/bin/expect<<-EOF
expect语句
expect eof
EOF
实例
#!/bin/bash
if [ $# == 3 ];then
user=$1
oldpasswd=$2
newpasswd=$3
/usr/bin/expect<<-EOF
spawn su $user
expect " :"
send " $oldpasswd\r"
expect eof
EOF
fi
注意:
/usr/bin/expect<<-EOF
expect语句
EOF
EOF部分要相互对应,即 EOF 是可变的,前后一致即可。
网友评论