TAGS :Viewed: 3 - Published at: a few seconds ago

[ How to stop new line conversion when zipping a Windows text file on a Unix machine ]

I want to zip a windows .cmd file on an OSX server, using the zip command line tool.

templateName="Windows_Project_Template"
zip -r -T -y -9 "${templateName}.zip" $templateName

When the file is unzipped on a windows machine all the new line carriage returns are converted and so the text file comes out without any new line formatting on a windows machine. How can I work around this?

Thanks

Answer 1


While not a perfect solution (I can't find an option to handle everything as binary), you can force the \r\n with the --to-crlf option:

   -l
   --to-crlf
          Translate the Unix end-of-line character LF into the MSDOS convention CR LF. This option should not be used on binary  files.   This
          option  can  be  used  on  Unix  if the zip file is intended for PKUNZIP under MSDOS. If the input files already contain CR LF, this
          option adds an extra CR. This is to ensure that unzip -a on Unix will get back an exact copy of  the  original  file,  to  undo  the
          effect of zip -l.  See -ll for how binary files are handled.

Be careful, if the file already contains \r\n you will get \r\r\n.