Question
前段时间写脚本出现了$'\r': command not found
问题。
Solution
由于linux无法解析$'\r',
这其实是windows与linux系统的差异导致的。
因为linux上的换行符为\n,而windows上的换行符为\r\n。所以脚本到linux上就无法解析了。
通常的处理办法主要有2种:
- 处理办法1 set ff=unix
vi hello.sh
### Esc进入命令行运行模式
### : set ff=unix
- 处理办法2 dos2unix
dos2unix hello.sh
### 如果报command not found 是因为你没有安装,安装dos2unix插件即可。