bash string manipulation



${string#substring}
    Strips shortest match of $substring from front of $string.

${string##substring}
    Strips longest match of $substring from front of $string.

       1 stringZ=abcABC123ABCabc
       2 #       |----|
       3 #       |----------|
       4 
       5 echo ${stringZ#a*C}      # 123ABCabc
       6 # Strip out shortest match between 'a' and 'C'.
       7 
       8 echo ${stringZ##a*C}     # abc
       9 # Strip out longest match between 'a' and 'C'.

${string%substring}
    Strips shortest match of $substring from back of $string.

${string%%substring}
    Strips longest match of $substring from back of $string.
Last update:
2006-09-27 23:37
Author:
Daniel
Revision:
1.0
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.