0

I am trying to unzip folder using shell script file(.sh). it is extracting files in the zip folder, but my destination directory created ends with ^M,

I am using this command in .sh file

unzip /tmp/mram/zip/ApNonProjectExpVO.zip -d /tmp/mram/zip/

and showing logs in putty as

Test.sh

Tue Jan 10 23:21:21 CST 2017

Archive:  /tmp/mram/zip/ApNonProjectExpVO.zip
   creating: /tmp/mram/zip/^M/ApNonProjectExpVO/
  inflating: /tmp/mram/zip/^M/ApNonProjectExpVO/ApNonProjectExpVO.xml
5
  • 1
    That sounds like the problem was caused at the zip creation, not during extraction. Commented Jan 11, 2017 at 5:51
  • 3
    There is likely a folder inside the zip file with that name.
    – Dan
    Commented Jan 11, 2017 at 6:02
  • Do you have the same output when extracting with Winzip/7zip in Windows? Commented Jan 11, 2017 at 7:58
  • 1
    @JuliePelletier, Dan: No, the CR evidently comes from the unzip line in the script. Commented Jan 11, 2017 at 22:51
  • @Gilles: Nice catch! Commented Jan 12, 2017 at 3:29

2 Answers 2

2

The argument of the -d option tells unzip in what directory to put the file. Since you told unzip to put the file in a directory called /tmp/mram/zip/^M (where ^M is a carriage return), it did exactly what you told it to do.

Fix your script by removing all the CR characters at the end of lines, as they're likely to cause other problems. In Unix, CR is an ordinary character, not part of an end-of-line marker like in Windows.

When you edit shell scripts under Windows, always remember to configure your editor to use Unix line endings (LF only).

-1

If you are writing your script in windows, Simplest thing you can do is open your script file in Notepad++ and Go to Edit > EOL Conversion > select Unix (LF) .

Remove any trailing spaces during rename and save. It should fix your problem :)

2
  • It is unclear what this adds beyond what the existing answer already says. If it's the instructions for how to make Notepad++ save Unix text, then this could be added as an edit to the existing answer. However, it is unclear whether the user in the question is using Notepad++.
    – Kusalananda
    Commented Mar 6, 2023 at 6:31
  • I see no mention of Windows or Notepad++. Maybe you can edit the question to clarify how exactly this addresses the issue, and what exactly it adds to the existing answer. Commented Mar 6, 2023 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .