#1879 Add unix2dos and dos2unix to MSYS-Base



In view of the recent independent inquiries, we might consider adding this pair of minimal implementations to msysCORE.

I suggest this particular pair, in preference to other suggestions, because:

1) They are extremely light weight.
2) They exploit only standard behaviour of an existing MSYS tool.
3) They have no dependency external to existing msysCORE.
4) They DTRT, without any added bells or whistles.



Issues: #1936


  • Keith Marshall

    Keith Marshall - 2008-10-28

    Implementation, as shell archive

  • Earnie Boyd

    Earnie Boyd - 2008-10-29

    These are found in the mingw-utils package and adding them to MSYS would conflict with that.

  • Keith Marshall

    Keith Marshall - 2008-10-29

    That we have had at least two independent inquiries as to where they may be found, in just the last week, suggests that it isn't entirely intuitive to look in mingw-utils, for filters to be used in MSYS.

    In any case, the package in mingw-utils is a native (and unnecessarily bloated, IMO) implementation. It should install in /mingw/bin, not in /bin, so where is the conflict? Personally, I prefer these light weight implementations to the versions in mingw-utils, (which I immediately junked after I installed that package).

    To avoid potential confusion, we could repackage as mingw32-unix2dos in mingw-utils, just as we did for mingw32-make, to distinguish it from make in MSYS.

    I see no problem with offering both, and allowing users to make their own choice, but ultimately, this is Cesar's call.

  • Cesar Strauss

    Cesar Strauss - 2008-11-11

    Thanks, Keith.

    However, you may have gone too far removing the bells and whistles...

    What I miss is:
    1) Ability to convert a file in-place, overwriting the original.
    2) Ability to convert a list of files in one go, e.g. 'dos2unix *.c'.


  • Keith Marshall

    Keith Marshall - 2008-11-11

    Hi Cesar,

    > What I miss is:
    > 1) Ability to convert a file in-place, overwriting the original.

    dos2unix foo.txt > foo.txt.$$ ; mv -f foo.txt.$$ foo.txt

    2) Ability to convert a list of files in one go, e.g. 'dos2unix *.c'.

    for file in *.c
    do dos2unix $file > $file.$$ ; mv -f $file.$$ $file

    The problem I have with building those bells and whistles directly into dos2unix and unix2dos is twofold:

    1) It breaks the MSYS paradigm of `minimalism'.
    2) More significantly, it breaks the concept of `maximally portable'.

    Ok, there is no definitive standard to which an implementation of this pair of tools should comply, (they aren't required by POSIX); thus, there are many incompatible implementations available, on various platforms. Solaris provides implementations which, (IIRC, but it has been a few years since I last used them), deliver exactly the functionality of my bare minimal filters, and no more. I also recall discussion in some GNU/Linux forum, which suggested a similar implementation, eschewing any additional functionality on the grounds of non-portability.

    That said, I'm not suggesting we discard the more advanced version from mingw-utils, nor that these minimal implementations should supersede that; rather, I'm suggesting that we bundle these minimal variants with MSYS, and users who install mingw-utils will automatically get the extended functionality. (Provided they continue to follow the time honoured advice to segregate MinGW and MSYS into separate trees, there is no conflict; that would only arise if they attempt to merge the two `bin' directories, in which case installing or upgrading MSYS *after* installing mingw-utils would revert to the minimal versions. To address that, it would probably be best to make the minimal variants an optional installation, with good comments in the installer to describe the limitations -- mingw-get is sorely needed here).

    As I've said, I'm using these implementations because I require something which is maximally portable; I'm offering them for general use, in the hope that they may be useful to others, but it's ultimately your choice whether or not to distribute them, and if you do, how it is done.


    BTW, just FTR, I understand that the mingw-utils implementations use Cygwin source. I consider that to be broken, because it doesn't function as a conventional UNIX filter; `dos2unix foo' does not write to stdout, as would normally be expected -- it implicitly converts in-place, which no other filter does. This is what I mean by breaking maximal portability, and it's the primary reason I've discarded the mingw-utils version from my own installation.

    If you want a more sophisticated implementation, I've attached an alternative shell script version, which mimics the Cygwin behaviour, in all respects except for the absence of the `-A' (a.k.a. `--auto') option.
    File Added: unix2dos.sh

  • Keith Marshall

    Keith Marshall - 2008-11-11

    Alternative, less minimal, shell script implementation

  • Cesar Strauss

    Cesar Strauss - 2008-11-11

    Hi Keith,

    Ah, I see you regard dos2unix more like a simple filter, while I regard it more like a stand-alone tool. IMHO, both cases are separately valid and useful, so we shouldn't allow one to exclude the other.

    How about this:

    1) Distribute your minimal version with MSYS, but rename them to short names like u2d and d2u, which reflects their minimal capabilities. Besides, other filters like sed and awk also have short 3-letter names...

    2) Keep the sophisticated version in mingw-utils, for those that like the current behavior. Leave their long names as is, to remind us of their fuller capabilities.


  • Keith Marshall

    Keith Marshall - 2008-11-12

    Hi Cesar,

    > Ah, I see you regard dos2unix more like a simple filter,

    Yep. That's how any UNIX implementation I've ever used has worked...

    > while I regard it more like a stand-alone tool.

    ...and this is how the Cygwin/mingw-utils implementations seem to want to work. Shame they didn't stick with established prior art, and use an option, (say `-O' or `--overwrite'), to invoke the `convert in-place' capability -- that would have avoided any incompatibility.

    > IMHO, both cases are separately valid and useful,
    > so we shouldn't allow one to exclude the other.

    Agreed. Your proposed combination should keep everyone happy; go for it!


  • Earnie Boyd

    Earnie Boyd - 2013-02-15

    Ticket moved from /p/mingw/feature-requests/59/

  • Earnie Boyd

    Earnie Boyd - 2013-02-15
    • labels: MSYS -->
    • status: open --> closed
    • milestone: Submitted --> MSYS
    • type: --> Feature
    • resolution: --> out-of-date
    • category: --> Unknown
    • patch_attached: --> False
  • Cesar Strauss

    Cesar Strauss - 2013-03-15

    Dear Keith,

    Sorry for not following up on this. We arrived at an agreement, but I failed to act on it.

    I'm still willing to add your original minimal implementation to msys-core.

    Unfortunately, msys-dos2unix already took the names we agreed upon (u2d and d2u). If you still want to distribute you scripts under new names, just let me know. Then, you can stil alias them locally if you want.


    cr++ / cr--
    cradd / crdel
    addcr / killcr
    w2u / u2w


  • Erwin Waterlander


    In principle I have no objection against removing d2u and u2d from dos2unix. I added d2u and u2d on Chuck's request, because he had added them to his version of dos2unix.

    On Linux and other OSes d2u/u2d are not part of dos2unix. Only on Cygwin and msys/mingw32. Chuck also maintained the same dos2unix for Cygwin. When his version was replaced with mine on Cygwin (this was before msys/mingw32 moved) I added d2u/u2d also for Cygwin.

    My reservations:

    I wonder if it is not too confusing for people if we now add Keith's d2u/u2d to msysCore and remove d2u/u2d from dos2unix. By now people may expect that d2u/u2d behaves the same as dos2unix/unix2dos. Which will be the case on Cygwin. Perhaps it is now too late to change it. Like Cesar I think it is best to use new command names.

    Maximum portability was used as an argument. I can say that the current dos2unix is the most portable there is. It is on most Linux distributions, spreading into Unixes, and used on Windows, FreeDOS, and OS/2.

    A note about in-place conversion.
    The most asked question for dos2unix is: "How do I convert files recursively in a directory tree?". With default in-place this is easy:

    find . -name '*.txt' -exec dos2unix {} \;

    This is also possible with Keith's version, but requires a lot more scripting.

    best regards,



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks