Updated as per Vidar from shellcheck.net.

Email received from Vidar:
Hi,

On line 53 in the script, getopt is used with -u:

 -u, --unquoted
     Do not quote  the  output.  Note  that  whitespace  and  special
     (shell-dependent)  characters can cause havoc in this mode (like
     they do with other getopt(1) implementations).

This havoc is basically what Shellcheck is warning about.

Unfortunately it's not simply a matter of quoting the variable, since the
underlying problem is the way getopt is used.

Instead of -u, you can use -s bash, and then eval instead of word split:

args=$(getopt -o hd:w:c:P: --long help,domain:,warning:,critical:,path: -s
bash -n "$PROGRAM" -- "$@")
...
eval "set -- $args"

This way, no havoc is caused, and no shellcheck errors are reported.

Regards,
Vidar
This commit is contained in:
Ryan Loudfoot 2013-11-03 18:11:48 -05:00
parent c6471330d6
commit 5f79f0f9f3

View File

@ -50,13 +50,13 @@ warning=30
#MONTH=("jan" "feb" "mar" "apr" "may" "jun" "jul" "aug" "sep" "oct" "nov" "dec")
# Parse arguments
args=$(getopt -o hd:w:c:P: --long help,domain:,warning:,critical:,path: -u -n "$PROGRAM" -- "$@")
args=$(getopt -o hd:w:c:P: --long help,domain:,warning:,critical:,path: -s bash -n "$PROGRAM" -- "$@")
if [ $? != 0 ]; then
echo >&2 "$PROGRAM: Could not parse arguments"
echo "Usage: $PROGRAM -h | -d <domain> [-c <critical>] [-w <warning>]"
exit 1
fi
set -- $args
eval "set -- $args"
die() {
local rc=$1