今天遇到了之前遇到过的问题 但是一时间竟然没想起怎么解决,记录一下,防止以后再忘。Windows下文本的换行和空格和linux下是有区别的 ,windows上的sh文件直接复制或者其他情况,在Linux下使用就会报

<pre class="has">

 "$'\r': command not found   
$'}\r': command not found
": no such file or directory

等错误


  
  
  
  
  
  
  
  
解决办法 安装 dos2unix

  
  
  
  
  
```
Centos 下 yum install dos2unix   

Ubuntu 下 apt install dos2unix   
```

  
  
  
然后转换文档格式

  
  
  
  
  
dos2unix 文件名

  
  
  
  
  
```
```
dos2unix  scp_static.sh 
```

  
  
  
spawn not found 错误

  
  
  
  
  
我在使用 spawn 时 报错

  
  
  
  
  
```
```
spawn: command not found
couldn't read file "*assword:": no such file or directory
scp_static.sh: line 17: *assword:: command not found
scp_static.sh: line 19: send: command not found
scp_static.sh: line 21: syntax error near unexpected token `}'
scp_static.sh: line 21: `}'

```

  
  
  
我在执行脚本的时候 用的 bash 命令 导致我自定义的命令解释器 #!/usr/bin/expect 并没有用上。可以使用 source 或者 ./执行脚本 但是 ./需要添加执行权限 chmod +x

  
  
  
  
  
```
```
chmod +x filename

./filename   

或者 source filename
```

  
  
  
也就是说使用 sh 或者 bash 时写在脚本最上面的 Shell 解释器没有生效而是使用了在当前bash环境下读取并执行

  
  
  
  
  
./ 首先会查找脚本第一行是否指定了解释器,如果没指定,那么就用当前系统默认的shell(大多数linux默认是bash),如果指定了解释器,那么就将该脚本交给指定的解释器

  
  
  
  
  
shell介于操作系统内核与用户之间,负责接收用户输入的操作指令(命令)并运行和解释,将需要执行的操作传递给操作系统内核并执行。 他是一种脚本语言(c) ,既然是一种语言 就如c 一样 需要自己的函数库,和特定的规则解释成二进制形式变成可执行文件。


标签: linux, scp, win, command, static, found, dos2unix, spawn, sh

相关文章推荐

添加新评论,含*的栏目为必填