url=http://www.foo.bar/file.ext; echo ${url##/*}
I expected this code to print file.ext
, but it prints the whole URL. Why? How can I extract the file name?
shellstring
url=http://www.foo.bar/file.ext; echo ${url##/*}
I expected this code to print file.ext
, but it prints the whole URL. Why? How can I extract the file name?
Best Answer
Because word has to match the string to be trimmed. It should look like:
Thanks derobert, you steered me in the right direction. Further, as @frank-zdarsky mentioned,
basename
is in the GNU coreutils and should be available on most platforms as well.