第一次写shell脚本

#!/usr/bin/expect
spawn ssh-keygen
expect {
        "Enter "{
        send "\r"
        exp_continue
        }
        "Enter "{ 
        send "\r"
        exp_continue
        }
        "Enter"{
        send "\r"
        }
}


这个是一个expect自动运行ssh-kegen脚本,这是我写的,运行之后,虽然不报错,但是却不执行

spawn ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 


研究了一个小时,百思不得其解。后来终于有高人指出问题所在,我的expect {}里面的 ""内容后没有空格,所以导致不运行就是说""空格{}这样再写,就会正常了。第一次写shell脚本,知道了shell连空格都很严格。