linux异常(六):expect错误 bash: spawn: command not found;couldn‘t read file

前言

问题出现的根源是执行脚本的姿势不对,伤害不大,侮辱性挺强,一起来看看吧!

如果,你对Expect的安装,及其精美案例,比较感兴趣,点击这里! 

报错信息

[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

问题根源

在执行脚本时,用的是#. file.exp(错误运行方法) 而不是 #./file.exp(正确运行方法)。

问题就出在这个斜杠上。

扩展

shell运行的5种方式

第一种使用绝对路径执行

第二种使用相对路径执行,如./的方式

第三种使用 sh命令来执行 格式 sh 脚本名 不需要执行权限 -x参数(显示执行过程)

第四种使用 . (空格)脚本名称的方式执行 不需要执行权限 . a.sh

第五种使用 source 脚本名称 不需要执行权限(主要用于生效配置文件)

案例中的expect用第四种方法 .(空格)来执行就会报错:  

[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

第二种,相对路径的方式执行就可以了(需要提前对脚本文件chmod +x  添加执行权限)。

注:普通的bash shell,以上5种执行方法均可,expect就没这么好使了,优先选第二种方式!

至此问题解决 

尾言

版本在迭代,学习的脚步不能停,一旦停下,储备知识可能就过时了,要做到时时新事事新,及时更新自己的技术储备,加油少年! 

如果你觉得还不错,赶快点赞收藏吧!

附注

1、Linux技巧(五):expect安装与介绍 | 精美案例 | 详解

猜你喜欢

转载自blog.csdn.net/xp871038951/article/details/127354159
今日推荐