curl .gz file and pipe it for decompression
A pipe (represented by the |
symbol) sends the standard output of one process to the standard input of another. In your case, you appear to want to use a named file so a pipe is not appropriate - specifically, there is nothing to pipe (hence the gunzip
error) because the remote contents are going to a local file. Instead, you'd need to extract the name of the file - for example, from its URL - something like (using bash's built in string manipulation capabilities)
curl -O "$URL" && gunzip -f "${URL##*/}"
If you want to use a pipe, then the way to do it would be something like
curl "$URL" | gunzip -c
(without the -O
option) so that curl
streams the remote contents to stdout
from where it can be piped into gunzip
, but then you would need to redirect the gunzip
output to overwrite the target uncompressed file as appropriate.
Follow redirects when downloading. Sometimes a web server has hidden redirects for security and/or random reasons. If you don't follow the redirect, the wrong data gets downloaded and your application reading the piped data gets confused. You can follow redirects with curl using the -L flag.
curl -L https://example.com/mygzip.tar.gz | tar zxv