首页  

shell执行时提示 $‘\r‘ 错误     所属分类 shell 浏览量 262
shell脚本是在Windows上写的,上传到Linux上,执行报$'\r'错误

unix 换行 LF(\n)
windows(CR LF)  \r\n 

cat –A filename  查看文件中的隐含字符
UNIX格式 每行结尾是 $ ,DOS格式 ^M$


用notepad++打开shell脚本,编辑->文档格式转换->转换为UNIX格式,然后保存

用vi命令打开脚本文件,命令行模式 输入 set fileformat=unix 回车,然后wq保存退出

删掉\r 后 ,文件大小会变小

set fileformat=dos 


demo.sh file=$1 echo "file=$file" cat $file |awk '{print $0}'
-rwxr-xr-x 1 root root 57 3月 8 21:39 demo2.sh -rwxr-xr-x 1 root root 54 3月 8 21:38 demo.sh -rw-r--r-- 1 root root 20 3月 8 21:38 hello.txt cat -A demo.sh file=$1$ echo "file=$file"$ cat $file |awk '{print $0}'$ cat -A demo2.sh file=$1^M$ echo "file=$file"^M$ cat $file |awk '{print $0}'^M$ ./demo.sh hello.txt ./demo2.sh hello.txt file=hello.txt : 没有那个文件或目录

上一篇     下一篇
Linux Shell 参数获取

光伏发电原理

采光权简介

linux awk 实例

awk 内建变量

置身事内笔记