Actually,
%% trims on the right.
let's consider this variable:
Quote:
var="the file system is full at 90%"
|
I want to get the last % off:
Quote:
echo ${var%%%}
the file system is full at 90
|
Now let's say I want to remove the last word. How do I do that?
Easy: I do exactly the same thing, but instead of removing %, I remove a space and anything that's after it (in regular expression, it means " *":
Oops! Actually, " *" matches just after the first word. That is because %% takes the biggest match possible.
Fortunatelly, I have another trick: the
% is the same as %%, but matches the smallest possible match:
Quote:
echo ${var% *}
the file system is full at
|
Good! I'm removed the last word.
But what if I want to remove the first word?
Well, there is another trick: the '
#' is exactly like '%' (and '
##' is like %%) but on the left:
Quote:
echo ${var##* }
90%
echo ${var#* }
file system is full at 90%
|
The documentation for this is in the bash documentation (man bash), which is very, VERY looooong.