Tynan Stevens wrote:
> David, could you explain to me the syntax of the second step of
> your bash code for extracting the degrees of freedom?
>
> I am interested in doing something similar to parse the maximum
> value of a dataset out of 3dinfo. I think I made it work by
> using something like:
>
> maximum=${maximum##*to}
>
From the bash man page:
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest matching pattern (the ``#'' case) or the longest matching pattern (the ``##'' case) deleted. If
parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an
array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``%'' case) or the longest matching pattern (the ``%%'' case)
deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If param-
eter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant
list.
For example,
maximum="footoblahbar"
then ${maximum##*to} will give you blahbar, that is foo is matched by * and to by to, the net effect is that footo is gobbled up by the variable expansion.
They are similar to, though considerably more powerful than, the the :r and :h variable modifiers in [t]csh.