foreword
The root of the problem is that the posture of executing the script is wrong, the damage is not big, but the insult is quite strong, let's take a look!
If you are more interested in the installation of Expect and its exquisite case , click here !
error message
[root@RHEL7 expect]# . ssh.exp
bash: spawn: command not found...
couldn't read file "{": no such file or directory
bash: yes/no: No such file or directory
root of the problem
When executing the script, use # . file.exp (the wrong way to run it) instead of # ./file.exp (the correct way to run it).
The problem lies in this slash.
expand
5 ways the shell works
The first one uses an absolute path to execute
The second way is to use a relative path, such as ./
The third is to use the sh command to execute the format. The sh script name does not require execution permission -x parameter (displays the execution process)
The fourth way to use . (space) script name execution does not require execution permission. a.sh
The fifth way to use the source script name does not require execution permission (mainly used for effective configuration files)
The expect in the case uses the fourth method . (space) to execute and an error will be reported:
[root@RHEL7 expect]# . ssh.exp
bash: spawn: command not found...
couldn't read file "{": no such file or directory
bash: yes/no: No such file or directory
The second way is to execute relative path (you need to add execution permission to the script file chmod +x in advance).
Note: For ordinary bash shell, the above five execution methods are all available, but expect is not so easy to use, the second method is preferred!
So far the problem is solved
Epilogue
The version is iterating, and the pace of learning cannot be stopped. Once you stop, the reserved knowledge may become outdated. You must keep new things new and update your technical reserves in time. Come on, young man!
If you think it's not bad, hurry up and like it!
notes
1. Linux skills (5): expect installation and introduction | Exquisite case | Detailed explanation