Ad
  • Default User Avatar

    %% is one of many Parameter Substitution Operators in BASH.

    Source: https://tldp.org/LDP/abs/html/parameter-substitution.html

    For context, here are my own practical descriptions of %%, %, ##, and #. I actually use these at the command line pretty often. Check out the source for definitive descriptions, as well as numerous examples.

    ${a%%b*} Remove the end of $a, from right to left, ending on the leftmost pattern that starts with "b"

    ${a%b*} Remove the end of $a, from right to left, ending on the rightmost pattern that starts with "b"

    ${a##*b} Remove the beginning of $a, from left to right, ending on the rightmost pattern that ends in "b"

    ${a#*b} Remove the beginning of $a, from left to right, ending on the leftmost pattern that ends in "b"

    Tips for remembering:

    On a standard US keyboard, # is to the left of %. Equivalently, % is to the right of #. This should help you remember which key to use.

    One # or % means non-greedy, whereas two means greedy. Two is more than one, which should help you remember ## and %% are greedy matches.