Use bash builtin string substitution instead, as suggested by:
https://github.com/koalaman/shellcheck/wiki/SC2001
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
dracut-module-setup.sh | 8 ++++----
mkdumprd | 18 ++++++++++--------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 8b9911d0..61ab9803 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -288,7 +288,7 @@ kdump_handle_mulitpath_route() {
while IFS="" read _route; do
if [[ "$_route" =~ [[:space:]]+nexthop ]]; then
- _route=$(echo "$_route" | sed -e 's/^[[:space:]]*//')
+ _route=${_route##[[:space:]]}
# Parse multipath route, using previous _target
[[ "$_target" == 'default' ]] && continue
[[ "$_route" =~ .*via.*\ $_netdev ]] || continue
@@ -372,7 +372,7 @@ kdump_setup_bridge() {
fi
_brif+="$_kdumpdev,"
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
@@ -388,7 +388,7 @@ kdump_setup_bond() {
echo -n " ifname=$_kdumpdev:$_mac" >>
${initdir}/etc/cmdline.d/42bond.conf
_slaves+="$_kdumpdev,"
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")
@@ -415,7 +415,7 @@ kdump_setup_team() {
echo -n " ifname=$_kdumpdev:$_mac" >>
${initdir}/etc/cmdline.d/44team.conf
_slaves+="$_kdumpdev,"
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!
#Try to use the latest version of teamd.
teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf
diff --git a/mkdumprd b/mkdumprd
index 64091cd8..2cb82396 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -58,7 +58,7 @@ add_dracut_sshkey() {
# caller should ensure $1 is valid and mounted in 1st kernel
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)
_fstype="${_fstype:-$(get_fs_type_from_target $_target)}"
@@ -67,9 +67,9 @@ to_mount() {
if [[ "$_fstype" == "nfs"* ]]; then
_pdev=$_target
- _options=$(echo $_options | sed 's/,addr=[^,]*//')
- _options=$(echo $_options | sed 's/,proto=[^,]*//')
- _options=$(echo $_options | sed 's/,clientaddr=[^,]*//')
+ _sed_cmd+='s/,addr=[^,]*//;'
+ _sed_cmd+='s/,proto=[^,]*//;'
+ _sed_cmd+='s/,clientaddr=[^,]*//;'
else
# for non-nfs _target converting to use udev persistent name
_pdev="$(kdump_get_persistent_dev $_target)"
@@ -79,13 +79,15 @@ to_mount() {
fi
# 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
# kernel, filter it out here.
- _options=$(echo $_options | sed 's/\(^\|,\)noauto\($\|,\)/\1/g')
+ _sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;'
# drop nofail or nobootwait
- _options=$(echo $_options | sed 's/\(^\|,\)nofail\($\|,\)/\1/g')
- _options=$(echo $_options | sed 's/\(^\|,\)nobootwait\($\|,\)/\1/g')
+ _sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;'
+ _sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;'
+
+ _options=$(echo "$_options" | sed "$_sed_cmd")
echo "$_pdev $_new_mntpoint $_fstype $_options"
}
--
2.31.1