I am still learning shell scripting. Recently I see a function for read configuration. But some of special character make me confused. I checked online to find answer. It was not successful. I post the code here to consult with expert or guru to get better understanding on these special characters such as: ^[^#]*=,line%%=*,line#*= . how to understand the usage of these special character here. Thanks.
read_cfg()
{��
while read line; do��
if [[ "$line" =~ ^[^#]*= ]]; then��
l_parameter=`echo ${line%%=*} | tr -d ' '` l_value=`echo ${line#*=} | tr -d ' '`��
��
case "$l_parameter" in ��
"EMAIL_LIST" ) �� #email list provided in command line overwrites the one in configuration file��
if [ -z "$g_bkp_email" ] ; then��
g_bkp_email=$l_value��
fi��
;;��
^[^#]*= is an extended regular expression and it means 0 or more non-# characters starting at the beginning of the line followed by an equal sign..
${line%%=*} is parameter expansion and it returns the characters to the left of the first = sign ${line#*=} is parameter expansion and it returns the characters to the right of the leftmost = sign
There's many great tools out there. One I recommend on a regular (bad pun) basis is https://regexr.com/. It includes a "deduced" explanation if you have an expression you find and paste in.