From d18bbc304e838ecf3b888ce4d70f1d96d21821f5 Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Fri, 7 Jun 2024 11:38:54 -0700 Subject: [PATCH 31/31] fix(dracut-functions): avoid awk in get_maj_min() The `get_maj_min()` cache lookup is commonly used across many flows. While `awk` should be available, some highly constrained environments may not have it. A second call to `grep` can provide the same behaviour without adding a dependnecy. Lines in the cache will be of the form "/dev/sda2 8:2". `awk '{print $NF}'` returns the last word of a matching line. Since the initial matching regex is so specific a second call to grep can easily extract the last word. (cherry picked commit ec7efd5701e9a1b24f2e85666d625fb1fe46ce86) Related: RHEL-47145 --- dracut-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dracut-functions.sh b/dracut-functions.sh index 43d905e3..b4d57454 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -243,7 +243,7 @@ get_maj_min() { local _out if [[ $get_maj_min_cache_file ]]; then - _out="$(grep -m1 -oE "^${1//\\/\\\\} \S+$" "$get_maj_min_cache_file" | awk '{print $NF}')" + _out="$(grep -m1 -oE "^${1//\\/\\\\} \S+$" "$get_maj_min_cache_file" | grep -oE "\S+$")" fi if ! [[ "$_out" ]]; then -- 2.42.0