mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
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
This commit is contained in:
parent
943c62a5d4
commit
95e5fe6732
1 changed files with 2 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue