bash scripts: always use "read -r"

upstream: fedora
resolves: bz2003832
conflict: none

commit a416930706
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:50:30 2021 +0800

    bash scripts: always use "read -r"

    This helps to strip spaces and avoid mangling backslashes:

    https://github.com/koalaman/shellcheck/wiki/SC2162

    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:22:51 +08:00
parent d07b20d718
commit 67611bba2a
3 changed files with 9 additions and 9 deletions

View File

@ -106,7 +106,7 @@ kdump_setup_dns() {
[ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile"
fi
while read content;
while read -r content;
do
_nameserver=$(echo $content | grep ^nameserver)
[ -z "$_nameserver" ] && continue
@ -265,7 +265,7 @@ kdump_static_ip() {
/sbin/ip $_ipv6_flag route show | grep -v default |\
grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\
while read _route; do
while read -r _route; do
_target=`echo $_route | cut -d ' ' -f1`
_nexthop=`echo $_route | cut -d ' ' -f3`
if [ "x" != "x"$_ipv6_flag ]; then
@ -286,7 +286,7 @@ kdump_handle_mulitpath_route() {
_ipv6_flag="-6"
fi
while IFS="" read _route; do
while IFS="" read -r _route; do
if [[ "$_route" =~ [[:space:]]+nexthop ]]; then
_route=${_route##[[:space:]]}
# Parse multipath route, using previous _target
@ -465,7 +465,7 @@ find_online_znet_device() {
for d in $NETWORK_DEVICES
do
[ ! -f "$d/online" ] && continue
read ONLINE < $d/online
read -r ONLINE < $d/online
if [ $ONLINE -ne 1 ]; then
continue
fi
@ -473,7 +473,7 @@ find_online_znet_device() {
# device is online)
if [ -f $d/if_name ]
then
read ifname < $d/if_name
read -r ifname < $d/if_name
elif [ -d $d/net ]
then
ifname=$(ls $d/net/)
@ -682,7 +682,7 @@ kdump_install_conf() {
kdump_read_conf > "${initdir}/tmp/$$-kdump.conf"
while read _opt _val;
while read -r _opt _val;
do
# remove inline comments after the end of a directive.
case "$_opt" in
@ -750,7 +750,7 @@ kdump_get_iscsi_initiator() {
[ -f "$initiator_conf" ] || return 1
while read _initiator; do
while read -r _initiator; do
[ -z "${_initiator%%#*}" ] && continue # Skip comment lines
case $_initiator in

View File

@ -673,7 +673,7 @@ load_kdump()
check_ssh_config()
{
while read config_opt config_val; do
while read -r config_opt config_val; do
case "$config_opt" in
sshkey)
# remove inline comments after the end of a directive.

View File

@ -370,7 +370,7 @@ if [ -f "$keyfile" ]; then
SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile)
fi
while read config_opt config_val;
while read -r config_opt config_val;
do
# remove inline comments after the end of a directive.
case "$config_opt" in