Skip to content

Instantly share code, notes, and snippets.

@uuklanger
Last active October 30, 2019 16:15
Show Gist options
  • Save uuklanger/4d1e439986df889554467159c154ff9d to your computer and use it in GitHub Desktop.
Save uuklanger/4d1e439986df889554467159c154ff9d to your computer and use it in GitHub Desktop.
HOWTO - Convert DOS to UNIX format

Convert DOS file to UNIX Format

If you clone a repo to a windows system and want to run shell scripts like bash or zsh within the Windows Subsystem for Linux you might need to fix the end-of-line characters. This depends on if you preserve end-of-line characters based on what is in the repo or if you have your local repo auto manage that.

Use Translate to fix this

tr -d '\r' < a.txt > b.txt

Example

The following example takes two scripts used in word_search_kata that were cloned to a Windows 10 system in DOS format. Bash does not like DOS formatted files so they need converted.

  1. Rename the files. I like to prefix with "dos_"
  2. Run each file through tr being sure to redirect the output to a new file using hte original name (less "dos_").
  3. Run new bash script to ensure it behaves correctly.
mv run_all_unittests.bash dos_run_all_unittests.bash
mv run_word_search_on_all_csv_data.bash dos_run_word_search_on_all_csv_data.bash
tr -d '\r' < dos_run_all_unittests.bash > run_all_unittests.bash
./run_all_unittests.bash
tr -d '\r' < dos_run_word_search_on_all_csv_data.bash > run_word_search_on_all_csv_data.bash
./run_word_search_on_all_csv_data.bash

If you choose, you can delete "dos_" temp file once you are satisfied that the scripts run as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment