From f3ef15f3d4d306d249ec8915ddd61670481734d8 Mon Sep 17 00:00:00 2001 From: Thiago Canozzo Lahr Date: Tue, 23 Jul 2024 09:12:44 -0300 Subject: [PATCH] refactor: replace for by while --- lib/build_artifact_list.sh | 17 ++++++++--------- lib/list_artifacts.sh | 17 +++++++---------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/build_artifact_list.sh b/lib/build_artifact_list.sh index df21230..e507c21 100644 --- a/lib/build_artifact_list.sh +++ b/lib/build_artifact_list.sh @@ -15,14 +15,13 @@ _build_artifact_list() # some systems use busybox's find that not always support '-type f' # skip artifacts that are not applicable to the target operating system - __ba_OIFS="${IFS}"; IFS=" -"; - for __ba_item in ${__ba_artifact_list}; do - if [ -f "${__ba_item}" ] \ - && { grep -q -E "supported_os:.*all|${__ba_operating_system}" "${__ba_item}" 2>/dev/null || [ "${__UAC_IGNORE_OPERATING_SYSTEM:-false}" = true ]; }; then - echo "${__ba_item}" - fi - done - IFS="${__ba_OIFS}" + # shellcheck disable=SC2162 + echo "${__ba_artifact_list}" \ + | while read __ba_item || [ -n "${__ba_item}" ]; do + if [ -f "${__ba_item}" ] \ + && { grep -q -E "supported_os:.*all|${__ba_operating_system}" "${__ba_item}" 2>/dev/null || [ "${__UAC_IGNORE_OPERATING_SYSTEM:-false}" = true ]; }; then + echo "${__ba_item}" + fi + done } diff --git a/lib/list_artifacts.sh b/lib/list_artifacts.sh index 73da203..60f9e1e 100644 --- a/lib/list_artifacts.sh +++ b/lib/list_artifacts.sh @@ -40,16 +40,13 @@ _list_artifacts() find "${__oa_artifacts_dir}"/* -name "*.yaml" -print 2>/dev/null \ | sed -e "s|^${__oa_artifacts_dir}/||" 2>/dev/null else - __oa_OIFS="${IFS}" - IFS=" -" - __oa_artifacts_tmp=`find "${__oa_artifacts_dir}"/* -name "*.yaml" -print 2>/dev/null` - for __oa_item in ${__oa_artifacts_tmp}; do - if grep -q -E "supported_os:.*all|${__oa_os}" "${__oa_item}" 2>/dev/null; then - echo "${__oa_item}" | sed -e "s|^${__oa_artifacts_dir}/||" 2>/dev/null - fi - done - IFS="${__oa_OIFS}" + # shellcheck disable=SC2162 + find "${__oa_artifacts_dir}"/* -name "*.yaml" -print 2>/dev/null \ + | while read __oa_item || [ -n "${__oa_item}" ]; do + if grep -q -E "supported_os:.*all|${__oa_os}" "${__oa_item}" 2>/dev/null; then + echo "${__oa_item}" | sed -e "s|^${__oa_artifacts_dir}/||" 2>/dev/null + fi + done fi }