Ubuntu – What does a hash after a variable name do as an operator in bash

bash

I found this code:

EXTENSION="${i#*=}"

What it does is to take the variable $i, which is an argument for the script and copies everything after the character =. So if I do something like myscript.sh -e=wow, it copies wow to $EXTENSION. But I want to know what the symbols #*= mean in this order? It seems like #* is together the copy all after and = is the character after which it copies, or is it more complex?

Best Answer

That is an example of prefix removal. The general form is:

 ${variable#pattern}

which removes the shortest match to the glob pattern from the beginning of variable. In your case, pattern consists of (a) * which matches zero or more of any character, and (b) = which matches just =.

See man bash for more info.

Example

$ i='ab=cd'
$ echo "${i#a}" 
b=cd
$ echo "${i#*=}" 
cd