[root@host~]# sh go.sh go.sh: line 6: spawn: command not found couldn't read file "{": no such file or directory go.sh: line 8: *yes/no: No such file or directory go.sh: line 8: exp_continue}: command not found go.sh: line 9: *password:: command not found go.sh: line 10: syntax error near unexpected token `}' go.sh: line 10: `}' |
执行sh脚本出现这个错误的基本上都是初学者
在linux操作系统中执行sh脚本有两种方式,一种是将sh作为命令行参数,另一种是将脚本作为具有执行权限的可执行脚本。
将脚本作为sh的命令行参数运行的方式如下
sh script.sh 或 sh home/path/script.sh
将脚本作为具有执行权限的可执行脚本运行方式如下
首先使脚本文件具有可执行权限,执行下面代码
chmod a+x script.sh或chmod 755 script.sh
./script.sh或/home/path/script.sh
而作为sh命令行参数来运行,那么脚本的#!这一行就会失效,所以才会出现spawn not found 错误,所有上面的go.sh 脚本必须用./命令运行
[root@host~]# ./ go.sh spawn ssh uniapply@1.2.3.24 uniapply@1.2.3.24's password: Last login: Tue May 21 12:03:43 2019 from 12.13.2.4 |




