You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ayed Alkhashan edited this page May 15, 2026
·
6 revisions
Literal carriage return. Run script through tr -d '\r' .
Problematic code:
$ cat -v myscript#!/bin/sh^Mecho "Hello World"^M
Correct code:
$ cat -v myscript#!/bin/shecho "Hello World"
Rationale:
The script uses Windows/MS-DOS style \r\n line terminators instead of Unix-style \n terminators. The additional \r aka ^M aka carriage return characters will be treated literally, and results in all sorts strange bugs and messages.
You can verify this with cat -v yourfile and see whether or not each line ends with a ^M. To delete them, open the file in your editor and save the file as "Unix", "Unix/macOS Format", :set ff=unix or similar if it supports it.
If you don't know how to get your editor to save a file with Unix line terminators, you can use tr:
tr -d '\r'< badscript > goodscript
or
dos2unix badscript
This will read a script badscript with possible carriage returns, and write goodscript without them.