From 814c4896e5a7dab26d56b0d76551842b4ae6c2e8 Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Tue, 9 Jul 2024 09:07:30 +0200 Subject: [PATCH] fix: Fix exit status code 7 for the --list option (#212) The exit status code 7 invoked if there are no pending update when using the `-l/--list` option was not honored because of the `sed` part piped into the call of the `list_package` function. Indeed, piped commands are executed in their own subshell, so the subshell invoked by the `| sed` part is exited with status code 7 instead of the parent subshell (see https://www.gnu.org/software/bash/manual/html_node/Pipelines.html & https://relentlesscoding.com/posts/bash-commands-in-pipelines-subshells/ for more details). Given the very little benefit this `sed` part brings (namely removing the last blank line of the output for purely aesthetic reason), it's not worth wrapping our head too hard on this. Let's just drop it. This commit also adds an info message that there is no update available for the -l/--list option (if that's the case). Fixes https://github.com/Antiz96/arch-update/issues/211 --- src/script/arch-update.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/script/arch-update.sh b/src/script/arch-update.sh index c405b07..38b62a5 100755 --- a/src/script/arch-update.sh +++ b/src/script/arch-update.sh @@ -328,9 +328,9 @@ list_packages() { if [ -z "${packages}" ] && [ -z "${aur_packages}" ] && [ -z "${flatpak_packages}" ]; then state_up_to_date - if [ -z "${list_option}" ]; then - info_msg "$(eval_gettext "No update available\n")" - else + info_msg "$(eval_gettext "No update available\n")" + + if [ -n "${list_option}" ]; then exit 7 fi else @@ -796,7 +796,7 @@ case "${option}" in ;; -l|--list) list_option="y" - list_packages | sed '${/^$/d;}' + list_packages ;; -n|--news) show_news="y"