bash scripts: get rid of unnecessary sed calls

upstream: fedora
resolves: bz2003832
conflict: none

commit fdfad3102e
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>
This commit is contained in:
Tao Liu 2021-11-03 16:21:06 +08:00
parent 480de7c63d
commit d07b20d718
2 changed files with 14 additions and 12 deletions

View File

@ -288,7 +288,7 @@ kdump_handle_mulitpath_route() {
while IFS="" read _route; do while IFS="" read _route; do
if [[ "$_route" =~ [[:space:]]+nexthop ]]; then if [[ "$_route" =~ [[:space:]]+nexthop ]]; then
_route=$(echo "$_route" | sed -e 's/^[[:space:]]*//') _route=${_route##[[:space:]]}
# Parse multipath route, using previous _target # Parse multipath route, using previous _target
[[ "$_target" == 'default' ]] && continue [[ "$_target" == 'default' ]] && continue
[[ "$_route" =~ .*via.*\ $_netdev ]] || continue [[ "$_route" =~ .*via.*\ $_netdev ]] || continue
@ -373,7 +373,7 @@ kdump_setup_bridge() {
fi fi
_brif+="$_kdumpdev," _brif+="$_kdumpdev,"
done done
echo " bridge=$_netdev:$(echo $_brif | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/41bridge.conf echo " bridge=$_netdev:${_brif%,}" >> "${initdir}/etc/cmdline.d/41bridge.conf"
} }
# drauct takes bond=<bondname>[:<bondslaves>:[:<options>]] syntax to parse # drauct takes bond=<bondname>[:<bondslaves>:[:<options>]] syntax to parse
@ -389,7 +389,7 @@ kdump_setup_bond() {
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf
_slaves+="$_kdumpdev," _slaves+="$_kdumpdev,"
done done
echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf"
_bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options") _bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options")
@ -416,7 +416,7 @@ kdump_setup_team() {
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf
_slaves+="$_kdumpdev," _slaves+="$_kdumpdev,"
done done
echo " team=$_netdev:$(echo $_slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf"
#Buggy version teamdctl outputs to stderr! #Buggy version teamdctl outputs to stderr!
#Try to use the latest version of teamd. #Try to use the latest version of teamd.
teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf

View File

@ -58,7 +58,7 @@ add_dracut_sshkey() {
# caller should ensure $1 is valid and mounted in 1st kernel # caller should ensure $1 is valid and mounted in 1st kernel
to_mount() { to_mount() {
local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _pdev local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev
_new_mntpoint=$(get_kdump_mntpoint_from_target $_target) _new_mntpoint=$(get_kdump_mntpoint_from_target $_target)
_fstype="${_fstype:-$(get_fs_type_from_target $_target)}" _fstype="${_fstype:-$(get_fs_type_from_target $_target)}"
@ -67,9 +67,9 @@ to_mount() {
if [[ "$_fstype" == "nfs"* ]]; then if [[ "$_fstype" == "nfs"* ]]; then
_pdev=$_target _pdev=$_target
_options=$(echo $_options | sed 's/,addr=[^,]*//') _sed_cmd+='s/,addr=[^,]*//;'
_options=$(echo $_options | sed 's/,proto=[^,]*//') _sed_cmd+='s/,proto=[^,]*//;'
_options=$(echo $_options | sed 's/,clientaddr=[^,]*//') _sed_cmd+='s/,clientaddr=[^,]*//;'
else else
# for non-nfs _target converting to use udev persistent name # for non-nfs _target converting to use udev persistent name
_pdev="$(kdump_get_persistent_dev $_target)" _pdev="$(kdump_get_persistent_dev $_target)"
@ -79,13 +79,15 @@ to_mount() {
fi fi
# mount fs target as rw in 2nd kernel # mount fs target as rw in 2nd kernel
_options=$(echo $_options | sed 's/\(^\|,\)ro\($\|,\)/\1rw\2/g') _sed_cmd+='s/\(^\|,\)ro\($\|,\)/\1rw\2/g;'
# with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd # with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd
# kernel, filter it out here. # kernel, filter it out here.
_options=$(echo $_options | sed 's/\(^\|,\)noauto\($\|,\)/\1/g') _sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;'
# drop nofail or nobootwait # drop nofail or nobootwait
_options=$(echo $_options | sed 's/\(^\|,\)nofail\($\|,\)/\1/g') _sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;'
_options=$(echo $_options | sed 's/\(^\|,\)nobootwait\($\|,\)/\1/g') _sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;'
_options=$(echo "$_options" | sed "$_sed_cmd")
echo "$_pdev $_new_mntpoint $_fstype $_options" echo "$_pdev $_new_mntpoint $_fstype $_options"
} }