Commit 95e5fe67 authored by Daniel Black's avatar Daniel Black

wsrep_sst_common: parse_cnf - use awk rather than grep/cut/tail excessiveness

Test cases:

f($var) = awk -v var="${var}"  \
     'BEGIN { OFS=FS="="}
     { gsub(/_/,"-",$1); if ( $1=="--"var ) lastval=substr($0,length($1)+2) }
     END { print lastval }'

Missing input is blank:

$ echo '--var_aa=something' | f(var-b-not-ther)
(blank as expected)

All RHS of = is unmunged:

$ echo '--var_aa=password==_-$' | f(var-aa)
password==_-$

Mixed - and _ in var name:
$ echo '--var_aa-bb_cc=1' | f(var-aa-bb-cc)
1

No value returns blank line:
$ echo '--var_aa-bb_cc' | f(var-aa-bb-cc)
(blank line as expected)

Multiples return the last:
$  echo -e "--bb=cc\n--bb=dd" | f(bb)
dd
parent 943c62a5
......@@ -245,11 +245,10 @@ parse_cnf()
local reval=""
# normalize the variable names specified in cnf file (user can use _ or - for example log-bin or log_bin)
# then grep for needed variable
# then search for needed variable
# finally get the variable value (if variables has been specified multiple time use the last value only)
# TODO: get awk to do the grep/cut bits as well
reval=$($MY_PRINT_DEFAULTS "${group}" | awk -F= '{if ($1 ~ /_/) { gsub(/_/,"-",$1); print $1"="$2 } else { print $0 }}' | grep -- "--$var=" | cut -d= -f2- | tail -1)
reval=$($MY_PRINT_DEFAULTS "${group}" | awk -v var="${var}" 'BEGIN { OFS=FS="=" } { gsub(/_/,"-",$1); if ( $1=="--"var) lastval=substr($0,length($1)+2) } END { print lastval}')
# use default if we haven't found a value
if [ -z $reval ]; then
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment