如何将 "whitespace" 和 "OR" 条件与 bash 脚本匹配?

How to match "whitespace" and "OR" condition with bash script?

我想匹配 bash 中的条件,其中包含字符串中的 "whitespaces" 和 "OR" 条件。我无法做到,因为我是 shell 脚本的新手,请帮忙,因为它会在匹配 ${myarrlin[1]} 的地方循环。我得到 "Centrify is disabled" 但我希望这里的条件为真。这是我的代码:

FILE_CENT="/etc/nsswitch.conf" 
OS=`uname`    
if [[ $OS = 'Linux' ]]; then
 if [[ -e $FILE_CENT ]]; then
echo "nsswitch.conf found, Proceeding further..."
  while read -r LINE
  do
  if [[ $LINE =~ ^passwd ]]; then
  myarrlin=($LINE)
    if [[ ${myarrlin[1]} =~ ^(centrify)|(centrifydc)[[:space:]]* || ${myarrlin[1]} =~ [[:space:]]+(centrify)|(centrifydc)[[:space:]]* ]];  then
     echo "Centrify is enabled"
     else
     echo "Centrify is disabled"
    fi
  fi
  done < $FILE_CENT
else
echo "nsswitch.conf does not exist in $OS, cannot fetch CENTRIFY information!"
 fi 
fi

nsswitch.conf >>>

passwd:     centrify files
  or
passwd:     centrifydc files
  or
passwd:     files centrify
  or
passwd:     files centrifydc

你为什么这样做:myarrlin=($LINE) ?

如果你只是想知道该行是否包含centrify:

  while read -r LINE
  do
  if [[ ${LINE} =~ ^passwd ]]; then
    if [[ ${LINE} == *"centrify"* ]];  then
     echo "Centrify is enabled"
    else
     echo "Centrify is disabled"
    fi
  fi
  done < $FILE_CENT