Shellcheck 0.11.0 produces the same warning for gcore-1.in and
gstack-1.in:
In gcore-1.in line 74:
OPTARG="${OPTARG#'$OPT'}"
^----^ SC2016 (info): Expressions don't expand in single quotes, use double quotes for that.
In gstack-1.in line 67:
OPTARG="${OPTARG#$OPT}"
^--^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.
The code in question exists to handle long option with arguments by
hand, like `--foo=bar`, since that is not supported natively by getopts.
At that line, OPTARG would contain `foo=bar`, OPT would contain `foo`,
and we're trying to strip `$OPT` from the beginning of `$OPTARG`. For
this to work, OPT needs to be expanded, and therefore needs double
quotes (or no quotes at all, but then shellcheck complains).
This bug is harmless right now because we don't use long options with
arguments. I tested this by temporarily making gcore support
-o|--output:
o | output)
prefix=$OPTARG
;;
And verified that this works:
$ ./gcore --output=salut 51286
...
Saved corefile salut.51286
...
Change-Id: I025be574699d67b18ada9d73ce8f2aa0c87d5a0d
Reviewed-By: Sébastien Darche <sdarche@efficios.com>
Reviewed-By: Keith Seitz <keiths@redhat.com>
while getopts vhao:g:d:-: OPT; do
if [ "$OPT" = "-" ]; then
OPT="${OPTARG%%=*}"
- OPTARG="${OPTARG#'$OPT'}"
+ OPTARG="${OPTARG#"$OPT"}"
OPTARG="${OPTARG#=}"
fi
while getopts hv-: OPT; do
if [ "$OPT" = "-" ]; then
OPT="${OPTARG%%=*}"
- OPTARG="${OPTARG#'$OPT'}"
+ OPTARG="${OPTARG#"$OPT"}"
OPTARG="${OPTARG#=}"
fi