From bbc2cae2b32c34fe11b7101c72f71eff8757f05e Mon Sep 17 00:00:00 2001 From: Mark Grant Date: Mon, 10 Jul 2023 09:57:05 +0100 Subject: [PATCH] bash: Treat cli_extra_args as an array The proper way to treat the contents of $@ when assigned is as an array. Relying on IFS of a is not robust. See the link for further information. Link: https://www.shellcheck.net/wiki/SC2086 Signed-off-by: Mark Grant (cherry picked from commit 5f3a80164c3860fdb50e14744a169e9b60cd9903) Signed-off-by: Mark Grant --- src/prg/bash/agmaint.sh.in | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/prg/bash/agmaint.sh.in b/src/prg/bash/agmaint.sh.in index 62eaf15..99aadb4 100644 --- a/src/prg/bash/agmaint.sh.in +++ b/src/prg/bash/agmaint.sh.in @@ -82,6 +82,7 @@ # apt-get commands. # # 22/11/2021 MG 1.1.3 Tighten SPDX tag. # # 26/06/2023 MG 1.1.4 Fix shellcheck warnings. # +# 10/07/2023 MG 1.1.5 Treat cli_extra_args as an array. # # # ######################################################################### @@ -89,10 +90,10 @@ ################## # Init variables # ################## -readonly version=1.1.4 # Script version +readonly version=1.1.5 # Script version readonly packageversion=@pkgversion@ # Package version -cli_extra_args="" +cli_extra_args=() ############# @@ -202,7 +203,7 @@ proc_CL() # bash concatenates with a space, fine for later word splitting # on command line. # shellcheck disable=SC2124 - cli_extra_args=$@ + cli_extra_args=( "$@" ) fi } @@ -213,26 +214,22 @@ proc_CL() proc_CL "$@" -# shellcheck disable=SC2086 # Word splitting on space is required. -apt-get $cli_extra_args upgrade +apt-get "${cli_extra_args[@]}" upgrade status=$? output "apt-get upgrade completed with exit code: "$status $status std_cmd_err_handler $status -# shellcheck disable=SC2086 # Word splitting on space is required. -apt-get $cli_extra_args autoclean +apt-get "${cli_extra_args[@]}" autoclean status=$? output "apt-get autoclean completed with exit code: "$status $status std_cmd_err_handler $status -# shellcheck disable=SC2086 # Word splitting on space is required. -apt-get $cli_extra_args check +apt-get "${cli_extra_args[@]}" check status=$? output "apt-get check completed with exit code: "$status $status std_cmd_err_handler $status -# shellcheck disable=SC2086 # Word splitting on space is required. -apt-get $cli_extra_args autoremove +apt-get "${cli_extra_args[@]}" autoremove status=$? output "apt-get autoremove completed with exit code: "$status $status std_cmd_err_handler $status