why questionmark comes in the end of filename when i create .txt file through shell script? [duplicate]

流过昼夜 提交于 2021-02-09 05:52:01

问题


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?

I am trying below methods in bash script.

1) grep ERROR a1* > text.txt

2) touch 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?


回答1:


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

Or with dos2unix:

dos2unix my_script

Or sed:

sed -i 's/\r$//' my_script


来源:https://stackoverflow.com/questions/37566064/why-questionmark-comes-in-the-end-of-filename-when-i-create-txt-file-through-sh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!