From ed371f5f5ab00fb4ad0ed981ac9e598ab943b733 Mon Sep 17 00:00:00 2001 From: Igor Velkov <325961+iav@users.noreply.github.com> Date: Wed, 18 Feb 2026 10:28:14 +0200 Subject: [PATCH] (#9400 P3a) Replace useless cat with input redirection (#9404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (#9400 P3a) trap-logging: replace useless cat with direct file arguments - gzip < file → gzip -c file (direct argument, -c for stdout) - cat file | ansi2txt → ansi2txt < file (ansi2txt has no file argument) - Remove now-unnecessary shellcheck disable=SC2002 comments * (#9400 P3a) logging: replace useless cat with direct file argument - cat file | grep | sed → grep file | sed (grep accepts filename directly) - Remove now-unnecessary shellcheck disable=SC2002 comment * (#9400 P3a) initrd: replace useless cat with direct file argument - cat file | md5sum → md5sum file (md5sum accepts filename directly) * (#9400 P3a) write-device: replace useless cat with direct file argument - cat file | awk → awk file (awk accepts filename directly) - Remove now-unnecessary shellcheck disable=SC2002 comment * (#9400 P3a) export-logs: replace useless cat with direct file argument - cat file | sed → sed file (sed accepts filename directly) - Remove now-unnecessary shellcheck disable=SC2002 comment * (#9400 P3a) python-tools: replace cat subshell with $(> "${destination}/DEBIAN/control.new" + grep -vP '^(Maintainer|Version):' "${destination}/DEBIAN/control" >> "${destination}/DEBIAN/control.new" # Replace 'Debian' with 'Armbian'. sed -i "s/Debian/${VENDOR}/g" "${destination}/DEBIAN/control.new" diff --git a/lib/functions/general/python-tools.sh b/lib/functions/general/python-tools.sh index 557193a23f..caf948d42f 100644 --- a/lib/functions/general/python-tools.sh +++ b/lib/functions/general/python-tools.sh @@ -62,7 +62,7 @@ function prepare_python_and_pip() { display_alert "pip3 version" "${pip3_version_number}" "info" # Calculate the hash for the Pip requirements - python3_pip_dependencies_hash="$(echo "${HOSTRELEASE}" "${python3_version}" "${pip3_version_number}" "$(cat "${python3_pip_dependencies_path}")" | sha256sum | cut -d' ' -f1)" + python3_pip_dependencies_hash="$(echo "${HOSTRELEASE}" "${python3_version}" "${pip3_version_number}" "$(< "${python3_pip_dependencies_path}")" | sha256sum | cut -d' ' -f1)" declare non_cache_dir="/armbian-pip" declare python_pip_cache="${SRC}/cache/pip" diff --git a/lib/functions/image/initrd.sh b/lib/functions/image/initrd.sh index dbed932016..a189a176fc 100644 --- a/lib/functions/image/initrd.sh +++ b/lib/functions/image/initrd.sh @@ -70,7 +70,7 @@ update_initramfs() { awk '{print $2 " - " $1}' | sed -e "s|^${chroot_target}||g" | LC_ALL=C sort > "${initrd_cache_current_manifest_filepath}" - initrd_hash="$(cat "${initrd_cache_current_manifest_filepath}" | md5sum | cut -d ' ' -f 1)" # hash of the hashes. + initrd_hash="$(md5sum "${initrd_cache_current_manifest_filepath}" | cut -d ' ' -f 1)" # hash of the hashes. initrd_cache_key="initrd.img-${initrd_kern_ver}-${initrd_hash}" initrd_cache_file_path="${SRC}/cache/initrd/${initrd_cache_key}" display_alert "initrd cache hash" "${initrd_hash}" "debug" diff --git a/lib/functions/image/write-device.sh b/lib/functions/image/write-device.sh index 31c9841874..c457da7c4f 100644 --- a/lib/functions/image/write-device.sh +++ b/lib/functions/image/write-device.sh @@ -17,8 +17,7 @@ function write_image_to_device() { # create sha256sum if it does not exist. we need it for comparison, later. local if_sha="" if [[ -f "${image_file}.img.sha" ]]; then - # shellcheck disable=SC2002 # cat most definitely is useful. she purrs. - if_sha=$(cat "${image_file}.sha" | awk '{print $1}') + if_sha=$(awk '{print $1}' "${image_file}.sha") else if_sha=$(sha256sum -b "${image_file}" | awk '{print $1}') fi diff --git a/lib/functions/logging/export-logs.sh b/lib/functions/logging/export-logs.sh index bb3f8837e9..5682dbcddc 100644 --- a/lib/functions/logging/export-logs.sh +++ b/lib/functions/logging/export-logs.sh @@ -155,10 +155,9 @@ function export_ansi_logs() { # shellcheck disable=SC2001 # I saw, and I can't logfile_title="$(echo "${logfile_base}" | sed -e 's/^[^.]*\.[^.]*\.//')" - # shellcheck disable=SC2002 # cats, not useless, I like. cat <<- ANSI_ONE_LOGFILE >> "${target_file}" $(echo -e -n "${bright_blue_color}")### ${logfile_title} $(echo -e -n "${ansi_reset_color}") - $(cat "${logfile_full}" | sed -e "${prefix_sed_cmd}") + $(sed -e "${prefix_sed_cmd}" "${logfile_full}") ${dim_line_separator} ANSI_ONE_LOGFILE done diff --git a/lib/functions/logging/logging.sh b/lib/functions/logging/logging.sh index ed227c8af3..ab19781e2b 100644 --- a/lib/functions/logging/logging.sh +++ b/lib/functions/logging/logging.sh @@ -95,8 +95,7 @@ function logging_error_show_log() { local prefix_sed_cmd="s/^/${prefix_sed_contents}/;" CURRENT_LOGFILE="" display_alert " 👇👇👇 Showing logfile below 👇👇👇" "${logfile_to_show}" "err" - # shellcheck disable=SC2002 # my cat is great. thank you, shellcheck. - cat "${logfile_to_show}" | grep -v -e "^$" | sed -e "${prefix_sed_cmd}" 1>&2 # write it to stderr!! + grep -v -e "^$" "${logfile_to_show}" | sed -e "${prefix_sed_cmd}" 1>&2 # write it to stderr!! CURRENT_LOGFILE="" display_alert " 👆👆👆 Showing logfile above 👆👆👆" "${logfile_to_show}" "err" else diff --git a/lib/functions/logging/trap-logging.sh b/lib/functions/logging/trap-logging.sh index 792cd2f7cd..7ea764f7a3 100644 --- a/lib/functions/logging/trap-logging.sh +++ b/lib/functions/logging/trap-logging.sh @@ -58,8 +58,7 @@ function trap_handler_cleanup_logging() { zstdmt --quiet "${one_old_logfile}" -o "${target_archive_path}/${old_logfile_fn}.zst" reset_uid_owner "${target_archive_path}/${old_logfile_fn}.zst" else - # shellcheck disable=SC2002 # my cat is not useless. a bit whiny. not useless. - cat "${one_old_logfile}" | gzip > "${target_archive_path}/${old_logfile_fn}.gz" + gzip -c "${one_old_logfile}" > "${target_archive_path}/${old_logfile_fn}.gz" reset_uid_owner "${target_archive_path}/${old_logfile_fn}.gz" fi rm -f "${one_old_logfile}" @@ -97,8 +96,7 @@ function trap_handler_cleanup_logging() { # ASCII logs, via ansi2txt, if available. local ascii_log_file="${target_path}/log-${ARMBIAN_LOG_CLI_ID}-${ARMBIAN_BUILD_UUID}.log" if [[ -n "$(command -v ansi2txt)" ]]; then - # shellcheck disable=SC2002 # gotta pipe, man. I know. - cat "${ansi_log_file}" | ansi2txt >> "${ascii_log_file}" + ansi2txt < "${ansi_log_file}" >> "${ascii_log_file}" fi # Export Markdown assets, but not if in GHA and GHA_EXPORT_MD_SUMMARY != yes