Hi Kairui,
On Thu, 19 Aug 2021 19:39:13 +0800
Kairui Song <kasong(a)redhat.com> wrote:
Avoid duplicated echo / cut / grep call, just use sed.
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
dracut-module-setup.sh | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 53abdc75..5ccf2db5 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -523,9 +523,7 @@ kdump_get_ip_route()
kdump_get_ip_route_field()
{
- if `echo $1 | grep -q $2`; then
- echo ${1##*$2} | cut -d ' ' -f1
- fi
+ echo "$1" | sed -n -e
"s/\(^\|^.*\s\+\)\<$2\>\s\+\(\S\+\).*$/\2/p"
^^^^^^^^^^^^^^
I think you can abbreviate this to '^.*'
\< indicates the beginning of a word which means
that the character before $2 must not be any word
character (i.e. alphanumeric or underscore '_').
Thanks
Philipp
}
kdump_get_remote_ip()