Issue
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.
Solution
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
.
Answered By - VonC Answer Checked By - David Marino (WPSolving Volunteer)