Shell (almost) regexp variable substitution

${variable#pattern}

If the pattern matches the beginning of the variable’s value, delete the shortest part that matches and return the rest. ${variable##pattern}

If the pattern matches the beginning of the variable’s value, delete the longest part that matches and return the rest. ${variable%pattern}

If the pattern matches the end of the variable’s value, delete the shortest part that matches and return the rest. ${variable%%pattern}

If the pattern matches the end of the variable’s value, delete the longest part that matches and return the rest.

Leave a Reply