what does param mean in shellscript?

From the bash man page:

${parameter##word}
          Remove matching prefix pattern.  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  patâ
          tern  (the  ``##''  case)  deleted.  If parameter is @ or *, the
          pattern removal operation is applied to each positional  parameâ
          ter 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.

 ${parameter%%word}
          Remove matching suffix pattern.  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  posiâ
          tional  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.

So in conclusion, with your example in mind, param=${param## }; will remove the leading space from the variable param and ${parameter%%word} will remove the trailing space

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top