Skip to content

Commit

Permalink
bash: Treat cli_extra_args as an array
Browse files Browse the repository at this point in the history
The proper way to treat the contents of $@ when assigned is as an array.
Relying on IFS of a <space> is not robust. See the link for further
information.

Link: https://www.shellcheck.net/wiki/SC2086
Signed-off-by: Mark Grant <[email protected]>
(cherry picked from commit 5f3a801)
Signed-off-by: Mark Grant <[email protected]>
  • Loading branch information
m-grant-prg committed Jul 10, 2023
1 parent b714119 commit bbc2cae
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/prg/bash/agmaint.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@
# 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. #
# #
#########################################################################


##################
# 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=()


#############
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit bbc2cae

Please sign in to comment.