DEV Community

Cover image for How i spent 1 hour of my time for a line break in a Bash.
Tykok
Tykok

Posted on

2 3

How i spent 1 hour of my time for a line break in a Bash.

I hope this article will help you if you want to use Bash to create a small script.

So yes, I confirm, I spent 1 HOUR OF MY TIME for a little break.

'A panda rage'

Why this happening ?

Because line break in Windows are not the same for Linux and when you run your Bash script you can have an error like this :

'The problem'

And you can search for a long time in your codes, why this error appeared.

And this error appear just because the encoding of your file using the unicode of your line break is "CR+LF" (000D + 000A) instead of "LF" (000A).

CR is for "cariage return" and LF is for "line feed".

When you press enter, one of this Unicode is used. And Linux doesn't like the CR+LF because he represents all line endings by a LF and in my case, he gave me some problems.

How to solve it ?

To solve it, you have many solutions. The most easily it's to use your favorite IDE and change the line ending.

For exemple in VSCode it's at the bottom.
VSCode tips

If you use Git, you can use a file named .gitatttributes. You can in this file, specify to get what is the end of the line of a specific file.

*.sh        text eol=lf
*.md        text=auto
*.txt       text
Enter fullscreen mode Exit fullscreen mode

In the first line we declare the end of the lines for all files with .sh extension by LF.

And the last solution is to use the command dos2unix you can use to convert all lines endings of a file.

And you, have you ever have an absurd problem like that ?

Main sources :

The website solves my problems (and save me).

Microsoft explains line endings.


Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay