I have a bash script and I see in the code
${variable#!}
what it means? thanks a lot
I have a bash script and I see in the code
${variable#!}
what it means? thanks a lot
it removes the leading !
from the value of the variable.
an example would be:
kent$ foo='!!hello'
kent$ echo ${foo#!}
!hello
See http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion
${parameter#word}
The word is expanded to produce a pattern just as in filename expansion. If the pattern matches the beginning of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional 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, if $variable
begins with !
, it will return its content without the first !
. If not, it will return $variable
.