summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDaniel Black <grooverdan@users.sourceforge.net>2018-01-13 23:05:21 +1100
committerDaniel Black <grooverdan@users.sourceforge.net>2018-01-14 23:31:01 +1100
commit95e5fe6732d939bd4b43f3a02fe004d530653093 (patch)
tree2591e4d7959286a39254b13112c089193de7f9c3 /scripts
parent943c62a5d4729786cb310f4a6af226184eb26196 (diff)
downloadmariadb-git-95e5fe6732d939bd4b43f3a02fe004d530653093.tar.gz
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
Diffstat (limited to 'scripts')
-rw-r--r--scripts/wsrep_sst_common.sh5
1 files changed, 2 insertions, 3 deletions
diff --git a/scripts/wsrep_sst_common.sh b/scripts/wsrep_sst_common.sh
index eca1277f17e..9c85106a5cb 100644
--- a/scripts/wsrep_sst_common.sh
+++ b/scripts/wsrep_sst_common.sh
@@ -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