]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(dracut-functions): avoid awk in get_maj_min()
authorDaniel McIlvaney <damcilva@microsoft.com>
Fri, 7 Jun 2024 18:38:54 +0000 (11:38 -0700)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Sun, 23 Jun 2024 01:01:44 +0000 (21:01 -0400)
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.

dracut-functions.sh

index f9e5d3bc6cb5abb7c72922314c90ad43de86bc35..1f7a90525b1fa1ab3ea1c40ae2c8a3f6fdb63610 100755 (executable)
@@ -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