Trying to remove leading and trailing blanks (SPC) from a variable's value using BASH, I feel that it does not work as described.
I started with ${var%% } and ${var## } which should remove the longest pattern, but it seems only one blank is removed:
% val="  a  ";echo "|${val}|${val## }|"
|  a  | a  |
% val="  a  ";echo "|${val}|${val%% }|"
|  a  |  a |
Then I tried pattern matching which seems no remove nothing (they also should repeatedly remove a blank at the start or end of the value):
% val="  a  ";echo "|${val}|${val//# }|"
|  a  |  a  |
% val="  a  ";echo "|${val}|${val//% }|"
|  a  |  a  |
I feel I made some simple mistake, but it seems I'm sitting on my eyes: Why doesn't this work?
(I did already visit these answers, but they did not include "my solution": How to trim whitespace from a Bash variable?, How to remove space from string?)
 
     
     
    