Search code examples
shellazureazure-storagewget

How to save file with filename alone while downloading files using wget


when I do wget as below, files are downloaded with filename as sample.txt?st=2017-07-19T06%3A00%3A00Z"

wget "https://sample.blob.core.windows.net/test/sample.txt?st=2017-07-19T06%3A00%3A00Z"

I don't want to use like below as It doesn't suits for my scenario.

wget -O $filename -q "https://sample.blob.core.windows.net/test/sample.txt?st=2017-07-19T06%3A00%3A00Z"

But I want to save filename as sample.txt when downloading using wget command. How to achieve this?


Solution

  • If my understanding is right, following script should work.

    ##set your blob url
    url="https://sample.blob.core.windows.net/test/sample.txt?st=2017-07-19T06%3A00%3A00Z"
    filename="${url%%[?]*}"; filename="${filename##*/}"
    
    wget -O $filename -q $url
    

    Note: If you use this script, your file name could not contain ?.