Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 495
vipul chauhan Avatar asked Jun 01 '16 10:06

vipul chauhan


People also ask

Why there is * At the end of file name?

It means that the file is executable.

What does EOF mean in script?

The EOF operator is used in many programming languages. This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended.

How do you create a text file in bash?

To create a new file, run the "cat" command and then use the redirection operator ">" followed by the name of the file. Now you will be prompted to insert data into this newly created file. Type a line and then press "Ctrl+D" to save the file.


1 Answers

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 with GNU sed:

sed -i 's/\r$//' my_script
like image 85
Andreas Louv Avatar answered Sep 29 '22 20:09

Andreas Louv