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?
Because word has to match the string to be trimmed. It should look like:
Thanks derobert, you steered me in the right direction. |
|||||
|
To quote the manpage:
A trivial way to do what you're looking for (according to your comment) is Another way to do what you want might be to use the pattern |
||||
|
See also: Bash Extended Globbing, though in this case the extended glob is not essential.
Output: |
||||
|
dirname $url
. Orgrep -o 'http://[^/]*' <<<$url
. – Kevin Feb 11 '13 at 15:04