当我通过Shell脚本创建.txt文件时,为什么questionmark位于文件名的末尾? [英] why questionmark comes in the end of filename when i create .txt file through shell script?
问题描述
我正在编写一个shell脚本,应该在其中创建1个文本文件.当我这样做时,文件名的末尾会出现一个问号.是什么原因?
I am writing one shell script in which I am supposed to create 1 text file. When I do this, a question mark comes at the end of file name. what is the reason?
我正在尝试以下bash脚本中的方法.
I am trying below methods in bash script.
1) grep ERROR a1 *>text.txt
2) touch text.txt
在这两种方法中,都有一个文件生成为 text.txt?
In both the methods, instead of text.txt
, there is a file generated as text.txt?
我该怎么做才能克服这个问题?
what should I do to overcome this?
推荐答案
像脚本一样的声音使用 \ r \ n
作为行尾,这是典型的DOS风格的行尾.类似Unix的系统使用 \ n
.您应该尝试更改换行符,例如使用您喜欢的文本编辑器:
Sounds like you script uses \r\n
as line endings, this is typical DOS style line endings. Unix like systems uses \n
. You should try to change the line feeds, eg with your favorite text editor:
vim +'set ff=unix | x' my_script
或使用 dos2unix
:
dos2unix my_script
或使用GNU sed:
Or with GNU sed:
sed -i 's/\r$//' my_script
这篇关于当我通过Shell脚本创建.txt文件时,为什么questionmark位于文件名的末尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!