d07b20 bash scripts: get rid of unnecessary sed calls

Authored and Committed by liutgnu 3 years ago
    bash scripts: get rid of unnecessary sed calls
    
    upstream: fedora
    resolves: bz2003832
    conflict: none
    
    commit fdfad3102e0d0564a7f26f7a3f25596d12502481
    Author: Kairui Song <kasong@redhat.com>
    Date:   Wed Aug 4 15:46:27 2021 +0800
    
        bash scripts: get rid of unnecessary sed calls
    
        Use bash builtin string substitution instead, as suggested by:
        https://github.com/koalaman/shellcheck/wiki/SC2001
    
        Signed-off-by: Kairui Song <kasong@redhat.com>
        Acked-by: Philipp Rudo <prudo@redhat.com>
    
    Signed-off-by: Tao Liu <ltao@redhat.com>
    
        
file modified
+4 -4
dracut-module-setup.sh CHANGED
@@ -288,7 +288,7 @@ kdump_handle_mulitpath_route() {
288
288
289
289
while IFS="" read _route; do
290
290
if [[ "$_route" =~ [[:space:]]+nexthop ]]; then
291
- _route=$(echo "$_route" | sed -e 's/^[[:space:]]*//')
291
+ _route=${_route##[[:space:]]}
292
292
# Parse multipath route, using previous _target
293
293
[[ "$_target" == 'default' ]] && continue
294
294
[[ "$_route" =~ .*via.*\ $_netdev ]] || continue
@@ -373,7 +373,7 @@ kdump_setup_bridge() {
373
373
fi
374
374
_brif+="$_kdumpdev,"
375
375
done
376
- echo " bridge=$_netdev:$(echo $_brif | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/41bridge.conf
376
+ echo " bridge=$_netdev:${_brif%,}" >> "${initdir}/etc/cmdline.d/41bridge.conf"
377
377
}
378
378
379
379
# drauct takes bond=<bondname>[:<bondslaves>:[:<options>]] syntax to parse
@@ -389,7 +389,7 @@ kdump_setup_bond() {
389
389
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf
390
390
_slaves+="$_kdumpdev,"
391
391
done
392
- echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf
392
+ echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf"
393
393
394
394
_bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options")
395
395
@@ -416,7 +416,7 @@ kdump_setup_team() {
416
416
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf
417
417
_slaves+="$_kdumpdev,"
418
418
done
419
- echo " team=$_netdev:$(echo $_slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf
419
+ echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf"
420
420
#Buggy version teamdctl outputs to stderr!
421
421
#Try to use the latest version of teamd.
422
422
teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf
file modified
+10 -8
mkdumprd CHANGED
@@ -58,7 +58,7 @@ add_dracut_sshkey() {
58
58
59
59
# caller should ensure $1 is valid and mounted in 1st kernel
60
60
to_mount() {
61
- local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _pdev
61
+ local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev
62
62
63
63
_new_mntpoint=$(get_kdump_mntpoint_from_target $_target)
64
64
_fstype="${_fstype:-$(get_fs_type_from_target $_target)}"
@@ -67,9 +67,9 @@ to_mount() {
67
67
68
68
if [[ "$_fstype" == "nfs"* ]]; then
69
69
_pdev=$_target
70
- _options=$(echo $_options | sed 's/,addr=[^,]*//')
71
- _options=$(echo $_options | sed 's/,proto=[^,]*//')
72
- _options=$(echo $_options | sed 's/,clientaddr=[^,]*//')
70
+ _sed_cmd+='s/,addr=[^,]*//;'
71
+ _sed_cmd+='s/,proto=[^,]*//;'
72
+ _sed_cmd+='s/,clientaddr=[^,]*//;'
73
73
else
74
74
# for non-nfs _target converting to use udev persistent name
75
75
_pdev="$(kdump_get_persistent_dev $_target)"
@@ -79,13 +79,15 @@ to_mount() {
79
79
fi
80
80
81
81
# mount fs target as rw in 2nd kernel
82
- _options=$(echo $_options | sed 's/\(^\|,\)ro\($\|,\)/\1rw\2/g')
82
+ _sed_cmd+='s/\(^\|,\)ro\($\|,\)/\1rw\2/g;'
83
83
# with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd
84
84
# kernel, filter it out here.
85
- _options=$(echo $_options | sed 's/\(^\|,\)noauto\($\|,\)/\1/g')
85
+ _sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;'
86
86
# drop nofail or nobootwait
87
- _options=$(echo $_options | sed 's/\(^\|,\)nofail\($\|,\)/\1/g')
88
- _options=$(echo $_options | sed 's/\(^\|,\)nobootwait\($\|,\)/\1/g')
87
+ _sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;'
88
+ _sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;'
89
+
90
+ _options=$(echo "$_options" | sed "$_sed_cmd")
89
91
90
92
echo "$_pdev $_new_mntpoint $_fstype $_options"
91
93
}