A lot of website redirect URL to let you the last version of a binary.
For example:
wget https://download.mozilla.org/?product=firefox-aurora-latest-l10n&os=linux64&lang=fr
Will let you download the latest Firefox Developper Edition. Output file will be "firefox-50.0a2.fr.linux-x86_64.tar.bz2".
But
wget https://download.mozilla.org/?product=firefox-aurora-latest-l10n&os=linux64&lang=fr -P $HOME
will leads to an output filename like: "?product=firefox-aurora-latest-l10n&os=linux64&lang=fr".
So I will use:
wget https://download.mozilla.org/?product=firefox-aurora-latest-l10n&os=linux64&lang=fr -P $HOME --trust-server-names
to redirect to the good file name: "firefox-50.0a2.fr.linux-x86_64.tar.bz2".
But on the next update the filename will be different.
I'm currently writting a script so I need to download the file with the good filename.
My question is:
How can I get the downloaded filename in a $var in order to use it next for example to extract the archive?
Note : I can't use basename as the name is not in the URL.
Note 2 : I use --trust-server-names
because --content-disposition
is experimental and not reliable.
curl -L --head -w '%{url_effective}' http://repo1/xyz/LATEST 2>/dev/null | tail -n1
from Resolve filename from a remote URL without downloading a file. – noraj Aug 30 '16 at 18:04shopt -s extglob; url=http://www.foo.bar/file.ext; echo ${url##+(*/)}; shopt -u extglob
from Extract the base file name from a URL using bash. – noraj Aug 30 '16 at 18:05