1

I'm building a CI/CD script in GitLab and want to unzip a curl output in the current dir by piping the curl output into unzip.

All the answers I could find suggests wget, tar or other tools.

Here is what I have:

curl -L "$URL" | unzip - -d ./output

Result is "Can not find output.zip so obviously unzip doesen't understand the dash placeholder when piping.

esbenr
  • 1,356
  • 1
  • 11
  • 34

1 Answers1

1

If you have to use unzip (which might not support stdin, unless it is an option ordering issue, as in unzip -d ./ouput -), then it could be easier to break it down into two steps, as shown here

curl -L "$URL" > output.zip
unzip output.zip -d ./output

That, or using a dedicated script.


Check if you have the funzip command, which should be part of the unzip package. funzip is a filter for extracting from a ZIP archive in a pipe.

Here's how you can use it:

curl -L "$URL" | funzip > output

Note that funzip will only extract the first file in the zip archive. If your zip file contains more than one file, you will need to save the file first, or use a different method.

If you're required to use unzip, and your environment doesn't support other unzipping tools, you may need to write to a temporary file as an intermediate step:

curl -L "$URL" -o temp.zip && unzip temp.zip -d ./output && rm temp.zip

This downloads the file, unzips it, and then deletes the temporary zip file. This is not as efficient as piping directly from curl to unzip, but it's a common way to work around the lack of support for piping in unzip.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. This is actually what I ended up doing - and then deleting the temporary .zip-file after. But I'd really like to improve the script and avoid that. I'm bound to use unzip as that's what our shared runners support. – esbenr May 17 '23 at 08:49
  • 1
    @esbenr OK. I have edited the answer with additional suggestions. – VonC May 17 '23 at 09:55