MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
755 stars 436 forks source link

Passing --no-defaults to healthcheck.sh results in bash error #539

Closed dhaeckel closed 8 months ago

dhaeckel commented 8 months ago

Hi,

I noticed a bash error when running the following command as healthcheck

/usr/local/bin/healthcheck.sh --no-defaults --connect --innodb_initialized

This results in

/usr/local/bin/healthcheck.sh: line 60: 'file': syntax error: operand expected (error token is "'file'")
/usr/local/bin/healthcheck.sh: line 40: 'file': syntax error: operand expected (error token is "'file'")

I reproduced the issue with the following bash script, the issue stems from the quotes that is used in the parameter expansion

#! /usr/bin/bash
declare -A def
unset def # emulating behaviour in arg parsing
${def['file']:+--defaults-file=${def['file']}}

Whe stripping the qoutes from the array key in the param expansion the error is gone. I can create a PR for that.

Thanks

grooverdan commented 8 months ago

I'm thinking the unset def was too brutal. What do you think about:

diff --git a/healthcheck.sh b/healthcheck.sh
index 5a3136e..530483f 100755
--- a/healthcheck.sh
+++ b/healthcheck.sh
@@ -309,7 +309,7 @@ while [ $# -gt 0 ]; do
                        datadir=${1}
                        ;;
                --no-defaults)
-                       unset def
+                       def=()
                        nodefaults=1
                        ;;
                --defaults-file=*|--defaults-extra-file=*|--defaults-group-suffix=*)
dhaeckel commented 8 months ago

@grooverdan This does work in my reproduction script without generating an error, so I approve of this solution. Thanks for the rapid response. Should I close this issue?

grooverdan commented 8 months ago

I will when I commit a fix.

grooverdan commented 8 months ago

Thank you.