fix windows line endings
"bad interpreter: ^M" and odd characters: the file has Windows line endings (CRLF). Find them and change them to Unix ones (LF).
Steps
-
file script.shsays "with CRLF line terminators" when it has them
-
cat -A script.sh | headshows them as ^M$ at the ends of the lines
-
dos2unix script.shchange them, if dos2unix is installed
-
sed -i 's/\r$//' script.shthe same with sed
-
unix2dos file.txtthe other way, for Windows
Notes
- git can do it for you:
git config --global core.autocrlf input.
Commands used
dos2unixfilesed
Each has a page in lore: lore dos2unix opens it.
Related recipes
- count lines of codeHow many lines of code a project has, in total and by language.
- pretty-print jsonShow JSON indented and coloured, pick values out of it, from a file or a web request.
- read a file line by lineGo through a file's lines in a script, also split into fields, without losing spaces or backslashes.
- add up numbers in a fileSum a column of numbers, from a file or a command's output.