Quote:
Originally Posted by
dips_ag
Thank you so much Don for explaining in detail! Despite that I've one more doubt (please bear with me!)
But Y is an alphabet so wouldn't [:alnum:] matches that? and a dot . is already present in the list of allowable punctuations?
-dips
The first character in the bracket expression (
[![:alnum:] .,;:\'\"/\(\)_+=~@&*-]) is
! so this is a NON-matching bracket expression. This bracket expression matches any single character that is NOT alphanumeric, NOT a <space>, NOT a <period>, NOT a <comma>, NOT a <semicolon>, NOT a <colon>, NOT a <single-quote>, NOT a <double-quote>, NOT a <slash>, NOT an <open-parenthesis>, NOT a <closing-parenthesis>, NOT an <underscore>, NOT a <plus_sign>, NOT an <equal-sign>, NOT a <tilde>, NOT an <at-sign>, NOT an <ampersand>, NOT an <asterisk>, and NOT a <hyphen-dash> (in this case it matches the circumflex). So, if there is a string of characters starting with any zero or more characters followed by one character in that non-matching expression, the
${var#expression} will expand to the contents of the variable
var with the string up to and including the first character that matches the non-matching expression removed.
If there aren't any characters in the variable that match the non-matching expression, there is no match for the entire expression; so the variable is expanded without removing anything. And, if
${var#expression} expands to the same thing as
$var, we know that no character was found in
$var that you consider to be non-printable.