Crazy_Bash Crazy_Bash - 3 months ago 24
Linux Question

wget: downloaded file name

I'm writing a script for bash and I need to get the name of the downloaded file using wget and put the name into $string

for example if I downloading this file below, I want to put it's name mxKL17DdgUhcr.jpg to $string

wget http://pics.sitename.com/images/191211/mxKL17DdgUhcr.jpg
45439 (44K) [image/jpeg]
Saving to: «mxKL17DdgUhcr.jpg»

100%[===================================================================================================>] 45 439 --.-K/s в 0s

2011-12-20 12:25:33 (388 MB/s) - «mxKL17DdgUhcr.jpg» saved [45439/45439]

Answer

Use the basename command to extract the filename from the url. For example:

url=http://pics.sitename.com/images/191211/mxKL17DdgUhcr.jpg
filename=$(basename "$url")
wget "$url"