From 5b1b482e139e9b1959ec70335aa844c258a60f4e Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 18 Jan 2023 18:15:18 +0000 Subject: eapi-usage.sh: optimise + refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use Bash primitives (parameter expansion) to avoid cut/rev (2x) calls, as well as grep! - Switch to while/read/find loop for improved robustness over while which can have issues wrt globbing/special file names. Thanks to ulm for the suggestions. Thanks-to: Ulrich Müller Signed-off-by: Sam James --- eapi-usage.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/eapi-usage.sh b/eapi-usage.sh index e4b65b2..62e878f 100755 --- a/eapi-usage.sh +++ b/eapi-usage.sh @@ -32,12 +32,12 @@ cd eapi-usage || exit 1 ebegin "Finding ebuilds" ( - for ebuild in $(find "${REPO_PATH}/metadata/md5-cache" -mindepth 2 -maxdepth 2 -type f -name '*-[0-9]*') ; do - cpf=$(echo ${ebuild} | rev | cut -d/ -f1-2 | rev) - eapi=$(grep -oi "eapi=.*" ${ebuild} | sed -e 's:EAPI=::') - + while IFS= read -r ebuild ; do + cpf_eapi="${ebuild#${REPO_PATH}/metadata/md5-cache/}" + cpf="${cpf_eapi%%:*}" + eapi="${cpf_eapi##*:EAPI=}" echo "${cpf}" >> ${eapi}.txt - done + done < <(find "${REPO_PATH}/metadata/md5-cache" -mindepth 2 -maxdepth 2 -type f -name '*-[0-9]*' -exec grep '^EAPI=' {} +) ) || { eend $? || exit 1; } eend ${?} -- cgit v1.2.3-65-gdbad