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).

  • text
  • development

Steps

  1. file script.sh

    says "with CRLF line terminators" when it has them

  2. cat -A script.sh | head

    shows them as ^M$ at the ends of the lines

  3. dos2unix script.sh

    change them, if dos2unix is installed

  4. sed -i 's/\r$//' script.sh

    the same with sed

  5. unix2dos file.txt

    the other way, for Windows

Notes

  • git can do it for you: git config --global core.autocrlf input.

Commands used

  • dos2unix
  • file
  • sed

Each has a page in lore: lore dos2unix opens it.