I’m a bit confused about stripping out the filename of a URL using bash in a function. This is what I have written, but I’m new to this, and cant figure out if I have done it right.
function file_download()
{
filename={$1##*/}
tar xzf $filename
}
file_download "http://www.url.com/test.zip"
Should I be putting quotations around the “$1”?
The
$should be outside of the expression:This will give you
test.zip, as expected. Otherwise, you’ll get{http://www.url.com/test.zip##*/}instead.