Bash substrings – just can’t figure it out…

Johnny Rosenberg gurus.knugum at
Tue Jan 31 18:07:20 UTC 2012

I have read some about those built in substring tools built into Bash,
but still I don't understand them enough to use them.

Here's what I found at

Deletes shortest match of $substring from front of $string.

Deletes longest match of $substring from front of $string.”

I have an example here:
File="03. Rock Nuts.flac"
echo "${File##N*s}"

The result should be ”03. Rock .flac”, shouldn't it? Obviously not,
because the result is ”03. Rock Nuts.flac”, which is exactly the
original string.
So what am I missing?

What I originally really wanted to achieve was something quite
different: The opposite of the above; cutting out everything BUT
something. In this case I wanted to cut everything between ”. ” and
”.”, so that only ”Rock Nuts” is left in the example above. I know I
can do that very easily with awk, but how can I do it with the Bash
built in stuff?

Kind regards

Johnny Rosenberg

More information about the ubuntu-users mailing list