{"id":4650,"date":"2012-03-12T10:51:00","date_gmt":"2012-03-12T10:51:00","guid":{"rendered":""},"modified":"2026-04-18T22:48:55","modified_gmt":"2026-04-18T22:48:55","slug":"removing-windows-newline-in-bash-scripts","status":"publish","type":"post","link":"https:\/\/hellem.org\/wblog\/?p=4650","title":{"rendered":"Removing Windows newline in bash scripts"},"content":{"rendered":"<p>Had an issue with the &#8216;^M&#8217; characther in some files causing unwanted line breaks. Got some help from colleagues pointing out that it is a Windows line break. But &#8211; how to remove it in my bash script? Easy to do using <a href=\"http:\/\/www.cyberciti.biz\/faq\/tag\/linux-tr-example\/\">TR<\/a> told me, but no. Added <\/p>\n<p><!-- codeblock lang=\"bash\" line=\"1\" --><\/p>\n<pre><code>tmp=\"$(echo ${mLine} | tr -d '^M')\"<\/code><\/pre>\n<p><!-- \/codeblock --><\/p>\n<p>but no luck&#8230;after some struggle it turned out that I could not just write ^M, I had to add it to the script using CTRL + V, then immediately followed by CTRL+V. Using VI as the editor that was what I needed to do to add the newline character to my script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had an issue with the &#8216;^M&#8217; characther in some files causing unwanted line breaks. Got some help from colleagues pointing out that it is a Windows line break. But &#8211; how to remove it in my bash script? Easy to do using TR told me, but no. Added tmp=&#8221;$(echo ${mLine} | tr -d &#8216;^M&#8217;)&#8221; but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"class_list":["post-4650","post","type-post","status-publish","format-standard","hentry","category-work-geek"],"_links":{"self":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4650"}],"version-history":[{"count":1,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4650\/revisions"}],"predecessor-version":[{"id":12958,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4650\/revisions\/12958"}],"wp:attachment":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}